How can I detect whether a form was submitted via an AJAX post or just a browser submit in Pylons?
For example:
if 'name' in request.POST:
#Do something
Would be true if ‘name’ was submitted via ajax or just a regular post. How can I differentiate?
Thank you.
You can use
request.is_xhr.This relies on your javascript framework to set the
X-Requested-With: XMLHttpRequestheader, but that’s not bad since most frameworks like jquery add this header.