Opened 11 years ago

Closed 11 years ago

#6616 closed (fixed)

Adding Ajax Detection To HttpRequest

Reported by: Daniel Lindsley <polarcowz@…> Owned by: Philippe Raoult
Component: Core (Other) Version: master
Severity: Keywords:
Cc: cgrady@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When working in views, I've found it helpful if I can determine if the request was made using Ajax or not, so I can determine what kind of response to send (be it XML, JSON or flat HTML). Most major Javascript libraries/frameworks have standardized on sending the 'X-Requested-With' header with Ajax requests (the list is part of the documentation for the patch). Since this check can occur frequently, I'd like to call a built-in method on HttpRequest. This patch adds that method and some documentation surrounding its use.

I understand that the core team does not wish to align Django with any specific Javascript frameworks/technologies, which this patch does not do. It is agnostic to what you're using, easy for someone who does not use a major library to implement in their Javascript code and is related more toward server-side processing of the request.

Attachments (2)

is_ajax.diff (1.3 KB) - added by polarcowz@… 11 years ago.
Patch & Documentation.
is_ajax.2.diff (1.2 KB) - added by peter 11 years ago.
Just a tiny bit cleaner than the previous version.

Download all attachments as: .zip

Change History (6)

Changed 11 years ago by polarcowz@…

Attachment: is_ajax.diff added

Patch & Documentation.

comment:1 Changed 11 years ago by Collin Grady <cgrady@…>

Cc: cgrady@… added

Changed 11 years ago by peter

Attachment: is_ajax.2.diff added

Just a tiny bit cleaner than the previous version.

comment:2 Changed 11 years ago by Philippe Raoult

Needs tests: set
Owner: changed from nobody to Philippe Raoult
Triage Stage: UnreviewedAccepted

Looks good, I'll test tomorrow @work.

comment:3 Changed 11 years ago by Philippe Raoult

Needs tests: unset
Triage Stage: AcceptedReady for checkin

patch works as expected and is documented.

comment:4 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7334]) Fixed #6616 -- Added an is_ajax() method to HttpRequest that uses the de facto
standard header for detecting an XmlHttpRequest call. Thanks, Daniel Lindsley.

Note: See TracTickets for help on using tickets.
Back to Top