Ticket #6616: is_ajax.diff

File is_ajax.diff, 1.3 KB (added by polarcowz@…, 17 years ago)

Patch & Documentation.

  • django/http/__init__.py

     
    7979
    8080    def is_secure(self):
    8181        return os.environ.get("HTTPS") == "on"
     82   
     83    def is_ajax(self):
     84        return 'HTTP_X_REQUESTED_WITH' in self.META \
     85            and self.META['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
    8286
    8387    def _set_encoding(self, val):
    8488        """
  • docs/request_response.txt

     
    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   for the 'HTTP_X_REQUESTED_WITH' header for the string 'XMLHttpRequest'. The
     197   following major Javascript libraries send this header:
     198
     199   * Prototype
     200   * jQuery
     201   * Dojo
     202   * MochiKit
     203   * MooTools
     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
Back to Top