title: Django view not getting ajax request
body: <p>I have a script in my template that tries to send data to a django view during onbuttonclick event. My problem is that the request doesn't seem to make it to the view. The browser console sees the request properly and all, but the django view does't even return true when i call request.is_ajax().<br/>
  <br/> request.method returns GET instead of POST, and the data is empty. This behavior is persistent regardless of the request type.</p>
  <p><strong>html</strong></p>
  <pre><code>&lt;a onclick=&quot;setGetParameter(this)&quot; pid=&quot;some_id&quot;&gt;Some Text&lt;/a&gt;
  </code></pre>
  <p><strong>.js</strong></p>
  <pre><code>&lt;script&gt;
    var csrftoken = Cookies.get('csrftoken');
  
    function setGetParameter(el){
  
        var stuff = $(el).attr('pid');
  
        $.ajax({
          type: 'POST',
          headers: { &quot;X-CSRFToken&quot;: csrftoken },
          url: '/view_url/',        
          data: {'datatopass': stuff},
          success: function(response){
            alert(response);
          }
        });
    }
    &lt;/script&gt;
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>path('view_url/', views.test),
  path('', views.home),
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>def test(request): 
      output = request.is_ajax()
      return HttpResponse(output)
  </code></pre>