title: Ajax xhr onload not being called within django app
body: <p>I have a Django app with user posts. I am trying to add a 'like' / voting system. I had done this through complete page refreshes through a redirect where the vote was made then redirected back to the same page with the new vote / like total updates. I then was reading about ajax and how I could update part of a page without a full reload.</p>
  
  <pre class="lang-js prettyprint-override"><code>let up_vote = document.getElementById("up-vote").addEventListener('click', () =&gt; {
      console.log("clicked");
      let xhr = new XMLHttpRequest();
      xhr.open('GET', "{% url 'up-vote' %}", true);
      console.log(xhr);
      xhr.onload = () =&gt; {
          console.log("inside");
  
      };
      console.log("outside");
  });
  </code></pre>
  
  <p>So far my js looks like this. When I click on "up-vote", "clicked" is printed along with the xhr object. However, <code>onload</code> appears to never be called as "inside" is never printed but instead passes straight over to "outside". </p>
  
  <p>I have a feeling that the issue is to do with the URL path but I don't know how to get path properly.
  The basic file structure of this app is:</p>
  
  <pre><code>app
  |-static/app  
      |-scripts/*this js file*/  
      |-images  
      |-styles  
  |-templates/app  
      |-html files
  |-views.py *where the request is being made*
  |-urls.py
  </code></pre>
  
  <p>urls.py contains,</p>
  
  <pre><code>urlpatterns = [
      ...
      path('post/&lt;int:pk&gt;/up/', up_vote, name='up-vote'),
      ...
  ]
  
  </code></pre>
  
  <p>and the views.py contain,</p>
  
  <pre><code>@login_required()
  def up_vote(request, pk):
      print("HI")
      obj = get_object_or_404(Post, pk=pk)
      uid = request.user.id
      if not obj.votes.exists(uid):
          obj.votes.up(uid)
      data = {
          'votes': obj.votes.count()
      }
      return JsonResponse(data)
  </code></pre>
  
  <p>Any help or advice greatly appreciated :)</p>
  
  <p>p.s. I have also tried xhr.onreadystate which is what gives to the thought of the URL path being wrong.</p>