title: Simple ajax call doesnt work in django
body: <p>First of all, ive taken the time to read and understand javascript and ajax but even though my code should work when checking it up against other kind that seems to be exactly the same this still doesnt work. Im not doing anything fancy here, just returning a simple text file named info.text </p>
  
  <p>I'm using django and this is the simple view i created:</p>
  
  <pre><code>def ajax(request):
      return render(request, "base/info.text")
  </code></pre>
  
  <p>And this is the simple ajax/javascript code:</p>
  
  <pre><code>  1 var window, document, submitButton;
    2
    3 submitButton = document.getElementsByName("form")[0];
    4 submitButton.addEventListener("submit", fireAjaxRequest, false);
    5
    6 function handleResponse() {
    7     if (httpRequest.readyState === 4) {
    8         alert("response received...");
    9         try {
   10             alert("in try catch")
   11             if (httpRequest.status === 200) {
   12                alert(httpRequest.responseText);
   13             } else {
   14                 alert("Request failed, status code received from the server is: " + httpRequest.statusText);
   15             }
   16         }
   17         catch (exception) {
   18           alert("exception: " + exception.description);
   19         }
   20     }
   21 }
   22
   23 function fireAjaxRequest() {
   24     console.log("firing the ajax request...");
   25     httpRequest = new XMLHttpRequest();
   26
   27     if (! httpRequest) {
   28       alert("not able to create XMLHttpRequest");
   29     } else {
   30       console.log("created XMLHttpRequest");
   31     }
   32
   33     httpRequest.onreadystatechange = handleResponse;
   34     httpRequest.open("GET", "javascript/ajax", true);
   35     httpRequest.send(null);
   36     console.log("request sent, waiting for response...");
   37 }
  </code></pre>
  
  <p>I know console.log is better but it just clears the console.log right away when i clik the submit button.</p>
  
  <p>in the open() call i have also tried with "<a href="http://domain.com:8000/javascript/ajax" rel="nofollow">http://domain.com:8000/javascript/ajax</a>" in addition to "/javascript/ajax", that doesnt work either.</p>
  
  <p>The html code is:</p>
  
  <pre><code>  3   &lt;html&gt;
    4     &lt;head&gt;
    5         &lt;title&gt;Javascript testing&lt;/title&gt;
    6     &lt;/head&gt;
    7     &lt;body&gt;
    8         Welcome to my site
    9         &lt;br&gt;&lt;br&gt;
   11         &lt;br&gt;&lt;br&gt;
   12         &lt;form name="form"&gt;
   13             First name: &lt;input type="text" id="firstName"&gt;&lt;/input&gt;
   14             &lt;br&gt;
   15             Last name: &lt;input type="text" id="lastName"&gt;&lt;/input&gt;
   16             &lt;br&gt;
   17             &lt;input type="submit" id="submit" value="Send registration"&gt;
   18             &lt;br&gt;
   19         &lt;/form&gt;
   20     &lt;/body&gt;
   21     &lt;script type="text/javascript" src="{% static 'js/js_test.js' %}"&gt;&lt;/script&gt;
   22   &lt;/html&gt;
  </code></pre>
  
  <p>The urls.py is just pointing to the view above (^javascript/ajax).</p>
  
  <p>I cant figure out why this simple request isnt working, it doesnt make any sense.</p>
  
  <p>The output of the request.status is just 0 for some reason</p>