Django

Code

Ticket #6616 (closed: fixed)

Opened 5 months ago

Last modified 4 months ago

Adding Ajax Detection To HttpRequest

Reported by: Daniel Lindsley <polarcowz@gmail.com> Assigned to: PhiR
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: cgrady@the-magi.us Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

is_ajax.diff (1.3 kB) - added by polarcowz@gmail.com on 02/16/08 22:23:57.
Patch & Documentation.
is_ajax.2.diff (1.2 kB) - added by peter on 02/22/08 16:49:53.
Just a tiny bit cleaner than the previous version.

Change History

02/16/08 22:23:57 changed by polarcowz@gmail.com

  • attachment is_ajax.diff added.

Patch & Documentation.

02/22/08 16:30:48 changed by Collin Grady <cgrady@the-magi.us>

  • cc set to cgrady@the-magi.us.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

02/22/08 16:49:53 changed by peter

  • attachment is_ajax.2.diff added.

Just a tiny bit cleaner than the previous version.

03/18/08 19:02:39 changed by PhiR

  • owner changed from nobody to PhiR.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Accepted.

Looks good, I'll test tomorrow @work.

03/19/08 08:18:48 changed by PhiR

  • needs_tests deleted.
  • stage changed from Accepted to Ready for checkin.

patch works as expected and is documented.

03/20/08 02:16:17 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #6616 (Adding Ajax Detection To HttpRequest)




Change Properties
Action