Get POST data in django form AJAX from

前端 未结 5 637
甜味超标
甜味超标 2021-01-15 19:28

I\'m going to get parameter form AJAX request in Django, Here\'s what I\'m doing:

base.html:

{% csrf_tok
5条回答
  •  时光取名叫无心
    2021-01-15 19:50

    What's happening is that you haven't prevented the browser's default submit action from taking place. So your Ajax POST is done, but then immediately the browser itself POSTs - and, as Michal points out, your form doesn't include a name field, so the lookup fails.

    You need to do two things to fix this. Firstly, use e.preventDefault(); in your JS click method. Secondly, check for request.is_ajax() at the top of your view.

提交回复
热议问题