What replaced is_ajax() is django 4

3,817 views
Skip to first unread message

Jet Ezra

unread,
Feb 24, 2022, 2:09:13 AM2/24/22
to Django users
Hello team.
Am sending jquery requests in django 4 but I have just realised that checking if the requests were from jquery using is_ajax and then perform ajax related actions is not possible. What is replacing this, and why would such a cool feature be removed.

Thanks

Jason

unread,
Feb 24, 2022, 7:33:20 AM2/24/22
to Django users

Jet Ezra

unread,
Mar 7, 2022, 8:51:00 AM3/7/22
to Django users
Cool, all I have realised is that if someone is specifically doing a jquery powered application, they can just write it and use it on their own using the below code
```py
def is_ajax():
     return request.headers.get('x-requested-with') == 'XMLHttpRequest'
```

And that's it! It will start checking if the code was from jquery, but for none Jquery, the docs ellaborate more here https://docs.djangoproject.com/en/3.1/releases/3.1/#id2
Reply all
Reply to author
Forward
0 new messages