Opened 17 years ago

Closed 17 years ago

#6616 closed (fixed)

Adding Ajax Detection To HttpRequest

Reported by: Daniel Lindsley <polarcowz@…> Owned by: Philippe Raoult
Component: Core (Other) Version: dev
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

Description

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@… 17 years ago.
Patch & Documentation.
is_ajax.2.diff (1.2 KB ) - added by peter 17 years ago.
Just a tiny bit cleaner than the previous version.

Download all attachments as: .zip

Change History (6)

by polarcowz@…, 17 years ago

Attachment: is_ajax.diff added

Patch & Documentation.

comment:1 by Collin Grady <cgrady@…>, 17 years ago

Cc: cgrady@… added

by peter, 17 years ago

Attachment: is_ajax.2.diff added

Just a tiny bit cleaner than the previous version.

comment:2 by Philippe Raoult, 17 years ago

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

Looks good, I'll test tomorrow @work.

comment:3 by Philippe Raoult, 17 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

patch works as expected and is documented.

comment:4 by Malcolm Tredinnick, 17 years ago

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