Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:30:41+00:00 2026-05-28T03:30:41+00:00

I’m trying out jQuery to send POST and GET requests to Django. So far

  • 0

I’m trying out jQuery to send POST and GET requests to Django.

So far only GET is recognized, and POST I will get errors, and although GET works I cannot get the individual fields that I send to my Django app.

So I wonder what’s the problem, and how do I get POST to work?

views.py

def xhr_test(request):
    if request.is_ajax():
        if request.method == 'GET':
            message = "Hello GET Ajax"
            print request.GET
            print "hello"
        elif request.method == 'POST':
            message = "Hello POST Ajax"
            print request.POST
    else:
        message = "Hello"
    return HttpResponse(message)

template

<html>  
<head>  
  <title>Ajax with jQuery Example</title>  
  <script type="text/JavaScript" src="{{ MEDIA_URL }}js/jquery.js"></script>  
  <script type="text/JavaScript">  
  $(document).ready(function() {
    $("#generate").click(function() {
      $.get("/ajax_fetch/xhr_test", function(data) {
      // alert(data);
      });
    });

    $("#generate_post").click(function() {
      $.post("/ajax_fetch/xhr_test", {
        name: "Monty"
      }, function(data) {
          alert(data)
      });
    });
  });
  </script>  
<style type="text/css">  
    #wrapper {  
      width: 240px;  
      height: 80px;  
      margin: auto;  
      padding: 10px;  
      margin-top: 10px;  
      border: 1px solid black;  
      text-align: center;  
    }  
  </style>  
</head>  
<body>  
  <div id="wrapper">  
    <div id="quote"><p> </p></div> 
    <form method="get">
      <p><input type="text" name="user" /></p>
      <p><input type="submit" id="generate" value="Generate!" /></p>
    </form>

    <form method="post">{% csrf_token %}
      <p><input type="text" name="user" /></p>
      <p><input id="generate_post" type="submit" value="Click" /></p>
    </form>
  </div
</body>  
</html> 

Error trace

Exception happened during processing of request from ('127.0.0.1', 1625)
Traceback (most recent call last):

  File "c:\python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "c:\python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\python27\lib\site-packages\django\core\servers\basehttp.py", line 56
, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "c:\python27\lib\SocketServer.py", line 641, in __init__
    self.finish()
  File "c:\python27\lib\SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "c:\python27\lib\socket.py", line 301, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in y
ur host machine
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:30:42+00:00Added an answer on May 28, 2026 at 3:30 am

    Okay, I don’t want to adjust the question. So post my solution to the problem as an answer instead. Here’s the modified files

    template

      $(document).ready(function() {
        $("#generate").click(function() {
          $.get("/ajax_fetch/xhr_test",$("form:first").serialize(), function(data) {
              alert(data);
          });
          return false
        });
      });
    
    <form>{% csrf_token %}
          <p><input type="text" name="user" /></p>
          <p><input type="text" name="name" /></p>
          <p><input type="submit" id="generate" value="Generate!" /></p>
    </form>
    

    views.py

    def xhr_test(request):
        if request.is_ajax():
            if request.method == 'GET':
                message = "Hello GET Ajax"
                message += " "+request.GET.get('user', '')
                message += " "+request.GET.get('name', '')
            elif request.method == 'POST':
                message = "Hello POST Ajax"
                print "hello"
                message += " "+request.POST.get('user', '')
        else:
            message = "Hello"
        return HttpResponse(message)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.