Django

Code

Ticket #6616: is_ajax.2.diff

File is_ajax.2.diff, 1.2 kB (added by peter, 9 months ago)

Just a tiny bit cleaner than the previous version.

  • django/http/__init__.py

    old new  
    7979 
    8080    def is_secure(self): 
    8181        return os.environ.get("HTTPS") == "on" 
     82     
     83    def is_ajax(self): 
     84        return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' 
    8285 
    8386    def _set_encoding(self, val): 
    8487        """ 
  • docs/request_response.txt

    old new  
    189189   Returns ``True`` if the request is secure; that is, if it was made with 
    190190   HTTPS. 
    191191 
     192``is_ajax()`` 
     193   **New in Django development version** 
     194 
     195   Returns ``True`` if the request was made via an XMLHttpRequest by checking  
     196   the 'HTTP_X_REQUESTED_WITH' header for the string 'XMLHttpRequest'. The  
     197   following major Javascript libraries send this header: 
     198 
     199   * jQuery 
     200   * Dojo 
     201   * MochiKit 
     202   * MooTools 
     203   * Prototype 
     204   * YUI 
     205    
     206   If you write your own XMLHttpRequest, you will have to set this header  
     207   manually to use this method. 
     208 
    192209QueryDict objects 
    193210----------------- 
    194211