Add Request Header to jQuery Ajax Requests

Sometimes it is necessary to determine if a request was performed by a jQuery Ajax call or a normal request. Using ajaxSetup it is possible to add custom headers to all Ajax requests executed by jQuery.

   'beforeSend': function(xhr) {           
      xhr.setRequestHeader("AJAX", "true");

Server-side you can then check the request header to identify the type of request and output the appropriate response.

This entry was posted in Programming and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

* = Required