Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6616 -- Added an is_ajax() method to HttpRequest that uses the…

… de facto

standard header for detecting an XmlHttpRequest call. Thanks, Daniel Lindsley.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7334 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c0537a961fcf412ff284a838e4394fc537c14dcf 1 parent c01e6b8
Malcolm Tredinnick authored March 20, 2008
1  AUTHORS
@@ -245,6 +245,7 @@ answer newbie questions, and generally made Django that much better:
245 245
     michael.mcewan@gmail.com
246 246
     michal@plovarna.cz
247 247
     Mikko Hellsing <mikko@sorl.net>
  248
+    Daniel Lindsley <polarcowz@gmail.com>
248 249
     Orestis Markou <orestis@orestis.gr>
249 250
     Slawek Mikula <slawek dot mikula at gmail dot com>
250 251
     mitakummaa@gmail.com
3  django/http/__init__.py
@@ -82,6 +82,9 @@ def build_absolute_uri(self, location=None):
82 82
     def is_secure(self):
83 83
         return os.environ.get("HTTPS") == "on"
84 84
 
  85
+    def is_ajax(self):
  86
+        return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
  87
+
85 88
     def _set_encoding(self, val):
86 89
         """
87 90
         Sets the encoding used for GET/POST accesses. If the GET or POST
17  docs/request_response.txt
@@ -199,6 +199,23 @@ Methods
199 199
    Returns ``True`` if the request is secure; that is, if it was made with
200 200
    HTTPS.
201 201
 
  202
+``is_ajax()``
  203
+   **New in Django development version**
  204
+
  205
+   Returns ``True`` if the request was made via an XMLHttpRequest by checking
  206
+   the ``HTTP_X_REQUESTED_WITH`` header for the string *'XMLHttpRequest'*. The
  207
+   following major Javascript libraries all send this header:
  208
+
  209
+   * jQuery
  210
+   * Dojo
  211
+   * MochiKit
  212
+   * MooTools
  213
+   * Prototype
  214
+   * YUI
  215
+
  216
+   If you write your own XMLHttpRequest call (on the browser side), you will
  217
+   have to set this header manually to use this method.
  218
+
202 219
 QueryDict objects
203 220
 -----------------
204 221
 

0 notes on commit c0537a9

Please sign in to comment.
Something went wrong with that request. Please try again.