Opened 17 years ago
Closed 17 years ago
#6616 closed (fixed)
Adding Ajax Detection To HttpRequest
Reported by: | 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)
Change History (6)
by , 17 years ago
Attachment: | is_ajax.diff added |
---|
comment:1 by , 17 years ago
Cc: | added |
---|
by , 17 years ago
Attachment: | is_ajax.2.diff added |
---|
Just a tiny bit cleaner than the previous version.
comment:2 by , 17 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Triage Stage: | Unreviewed → Accepted |
Looks good, I'll test tomorrow @work.
comment:3 by , 17 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
patch works as expected and is documented.
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(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.
Patch & Documentation.