title: jquery post request + response in Django
body: <p>I am trying to make a post request with jquery in Django. Unfortunately I haven't succeeded yet. Indeed : I only see in firebug a post request which status is 200 and I get the following result (too new to post any image):</p>
  
  <p><a href="https://drive.google.com/a/essec.edu/file/d/0B5MagNFQFkbXeVBNV1pfZC1sbk0/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/a/essec.edu/file/d/0B5MagNFQFkbXeVBNV1pfZC1sbk0/view?usp=sharing</a></p>
  
  <p>Could anyone help me find what I have done wrong?</p>
  
  <p>My code comes from here :
  <a href="https://stackoverflow.com/questions/16814425/need-a-simple-working-ajax-example-for-django-forms">Need a simple working ajax example for django forms</a> , so I think it should be correct.</p>
  
  <p>FYI, in settings.py I have commented the csrf line to put away that issue for the time beeing :</p>
  
  <p>"    #'django.middleware.csrf.CsrfViewMiddleware',"</p>
  
  <p>views.py:</p>
  
  <pre><code>import json
  from django.shortcuts import render
  from django.http import HttpResponse
  
  
  def index(request):
  
      return render(request, 'index.html')
  
  
  def ajax_test(request):
      if request.method == 'POST' and request.is_ajax():
          name = request.POST['name']
          city = request.POST['city']
          message = name + ' lives in ' + city
  
          return HttpResponse(json.dumps({'message': message})) 
  
      return render(request, 'ajax.html')
  </code></pre>
  
  <p>index.html:</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="/static/js/ajax.js"&gt;&lt;/script&gt;
  &lt;script src="http://getbootstrap.com/dist/js/bootstrap.js"&gt;&lt;/script&gt;
  
  
  &lt;form id="my_form" action="" method="post"&gt;
  &lt;input type="submit" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>ajax.js:</p>
  
  <pre><code>$(document).ready(function(){
  
    $("#my_form").submit(function(){
      $.post("",
      {name:"Donald Duck",
       city:"Duckburg",
       },
      function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
      })
      .fail(function(xhr) {
          console.log("Error: " + xhr.statusText);
          alert("Error: " + xhr.statusText);
      });
      return false;
    });
  
  });
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>from django.conf.urls import patterns, url
  
  from polls import views
  
  urlpatterns = patterns('',
      url(r'^$', views.index, name='index'),
      url(r'^ajax/$', views.ajax_test, name="ajax"),
  )
  </code></pre>