Opened 7 years ago

Closed 7 years ago

#6616 closed (fixed)

Adding Ajax Detection To HttpRequest

Reported by: Daniel Lindsley <polarcowz@…> Owned by: PhiR
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: UI/UX:

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

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by polarcowz@…

Patch & Documentation.

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

  • Cc cgrady@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 7 years ago by peter

Just a tiny bit cleaner than the previous version.

comment:2 Changed 7 years ago by PhiR

  • Needs tests set
  • Owner changed from nobody to PhiR
  • Triage Stage changed from Unreviewed to Accepted

Looks good, I'll test tomorrow @work.

comment:3 Changed 7 years ago by PhiR

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

patch works as expected and is documented.

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to 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.

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