title: Django GET request in AJAX
body: <p>I need to get some HTML using AJAX.
  My view work fine as long as I use jQuery:</p>
  
  <h3>view.py</h3>
  
  <pre><code>def my_ajax(request):
      if request.is_ajax():
          my_form = MyForm()
          context = {
              'form': my_form
          }
          return render(request, 'myapp/form.html', context)
  </code></pre>
  
  <h3>main.js (jQuery load)</h3>
  
  <pre><code>$(document).ready(function() {
      $('#foo').click(function() {
          $('#bar').load('{% url "myapp:form" %}');
      });
  });
  </code></pre>
  
  <p>If I use the JavaScript <code>XMLHttpRequest</code> I have to remove <code>if request.is_ajax():</code> from the view otherwise I got the error <code>The view myapp.views.my_ajax didn't return an HttpResponse object. It returned None instead.</code></p>
  
  <h3>main.js (XMLHttpRequest)</h3>
  
  <pre><code>(function() {
      document.getElementById('foo').addEventListener("click", function() {
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
          if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
              document.getElementById("bar").innerHTML = xhttp.responseText;
          }
      };
      xhttp.open("GET", '{% url "myapp:form" %}', true);
      xhttp.send();
      }, false);
  })();
  </code></pre>
  
  <p>What I'm doing wrong in the <strong>XMLHttpRequest</strong>?
  I am surely missing something but I would like to use Vanilla JavaScript this time.
  Thanks!</p>