title: Can't do an AJAX call with Python and Django
body: <p>I am still learning to do javascript and django and yesterday I tried to do a simple hello world ajax exercise. </p>
  
  <p>Server logs show that python code is being called but somehow django/python does not return anything when I check the xmlhttp.responseText and responseXML in firebug. </p>
  
  <p><strong>UPDATE:</strong> I removed the checking of the http status returned so that code immediately goes to print the output from the server</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
   &lt;title&gt;Javascript example 1&lt;/title&gt;
   &lt;script type="text/javascript"&gt;
    function doAjax() 
    {
     xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function() {
         alert("response text: "+xmlhttp.responseText+"\n"
               +"response XML: "+ xmlhttp.responseXML);
         if (xmlhttp.responseText!="") {
              $("thediv").innerHTML=xmlhttp.responseText;
         }      
     }   
     xmlhttp.open("GET","http://127.0.0.1/test/",true);
     xmlhttp.send(); 
    }
    function $(element){
      return document.getElementById(element);
    }
   &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
   &lt;input type="button" value="click me" onClick=javascript:doAjax()&gt;
   &lt;br/&gt;&lt;br/&gt;
  
   &lt;div id="thediv"&gt;
    some test
   &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>my views.py</p>
  
  <pre><code>from django.http import HttpResponse
  
  def test(request):
   response_string="hello"
   return HttpResponse(response_string,mimetype='text/plain')
  </code></pre>
  
  <p>my urls.py</p>
  
  <pre><code>from django.conf.urls.defaults import *
  from project1.views import test
  
  # Uncomment the next two lines to enable the admin:
  # from django.contrib import admin
  # admin.autodiscover()
  
  urlpatterns = patterns('',
          (r'^test/$', test)
      # Example:
      # (r'^project1/', include('project1.foo.urls')),
  
      # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
      # to INSTALLED_APPS to enable admin documentation:
      # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
  
      # Uncomment the next line to enable the admin:
      # (r'^admin/', include(admin.site.urls)),
  )
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is the code in action </p>
  
  <p><img src="https://i.stack.imgur.com/rr0K1.png" alt="alt text"></p>