Django

Code

Changeset 7334

Show
Ignore:
Timestamp:
03/20/08 02:16:16 (4 months ago)
Author:
mtredinnick
Message:

Fixed #6616 -- Added an is_ajax() method to HttpRequest that uses the de facto
standard header for detecting an XmlHttpRequest? call. Thanks, Daniel Lindsley.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r7330 r7334  
    246246    michal@plovarna.cz 
    247247    Mikko Hellsing <mikko@sorl.net> 
     248    Daniel Lindsley <polarcowz@gmail.com> 
    248249    Orestis Markou <orestis@orestis.gr> 
    249250    Slawek Mikula <slawek dot mikula at gmail dot com> 
  • django/trunk/django/http/__init__.py

    r7257 r7334  
    8282    def is_secure(self): 
    8383        return os.environ.get("HTTPS") == "on" 
     84 
     85    def is_ajax(self): 
     86        return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' 
    8487 
    8588    def _set_encoding(self, val): 
  • django/trunk/docs/request_response.txt

    r7303 r7334  
    199199   Returns ``True`` if the request is secure; that is, if it was made with 
    200200   HTTPS. 
     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. 
    201218 
    202219QueryDict objects