title: How to handle AJAX POST request in Django
body: <p>I have a sort of twitter like button function in my app such that, when the button is clicked, it triggers an AJAX call and performs the action specified in the views. However, when i click the button, it does not perform action in views. The code reaches the 'like view' but does not execute anything after 'if request.POST:'. Please help.</p>
  
  <blockquote>
    <p><strong>Menu.html</strong></p>
  </blockquote>
  
  <pre><code>&lt;form action="{% url 'like'%}" id="plt_{{menu.id}}" data-id="{{menu.id}}" method="post"&gt;
          {%csrf_token%}
     &lt;input name="menu_id" type="hidden" value="{{ menu.id }}"&gt;
      &lt;div class="like-button" id="btn_{{menu.id}}"&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <pre><code>&lt;script&gt;
       $('.like-button').on('click', function () {
           var id = $(this).attr('id');
           id = id.replace('btn_','');
  
           $(this).toggleClass('animate').promise().done(function () {
              var link = $("#plt_"+id).attr('action')
                  $.ajax({
                      type: 'POST',
                      url: link,
                      headers: {'X-CSRFToken': '{{ csrf_token }}'},
                  })
                  });
      });
  
   &lt;/script&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>Views.py</strong></p>
  </blockquote>
  
  <pre><code>def like(request):
      print('reached') //this prints
      if request.POST:
       menu = Menu.objects.get(pk=request.POST.get('menu_id'))
       //execute code to like
       return HTTPResponse('')
  
  </code></pre>