Django throws error no. 10053 when receiving POST from jQuery



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?

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
        message = "Hello"
    return HttpResponse(message)


  <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) {
<style type="text/css">  
    #wrapper {  
      width: 240px;  
      height: 80px;  
      margin: auto;  
      padding: 10px;  
      margin-top: 10px;  
      border: 1px solid black;  
      text-align: center;  
  <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 method="post">{% csrf_token %}
      <p><input type="text" name="user" /></p>
      <p><input id="generate_post" type="submit" value="Click" /></p>

Error trace

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

  File "", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "", line 310, in process_request
    self.finish_request(request, client_address)
  File "", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "", line 56
, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "", line 641, in __init__
  File "", line 694, in finish
  File "", line 301, in flush
error: [Errno 10053] An established connection was aborted by the software in y
ur host machine






<input id="generate_post" type="submit" value="Click" />


<input id="generate_post" type="button" value="Click" />

(Change submit to button)


[], [], [], []

Facebook Comments

Post a comment