Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: how to distinguish AJAX POST request?

Tags:

jquery

django

I have a form that gets submitted using jQuery's .post().

In the corresponding view function, is there a way that I can use to determine that the requested received is AJAX?

I have seen code snippet dated back to 2006, which uses

request.GET.has_key('xhr')

But I don't see anything in my request.GET. I am guessing the above might be obsolete.

Please advise what I can do to achieve my purpose. Thanks.

like image 352
tamakisquare Avatar asked Aug 11 '11 21:08

tamakisquare


1 Answers

request.is_ajax()

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.is_ajax

like image 103
Mikhail Korobov Avatar answered Oct 12 '22 10:10

Mikhail Korobov