jQuery unveiled: the ajaxSettings class

ajaxSettings is a private jQuery class used to handle all the details of an Ajax connection. It is as follows:

ajaxSettings: {
  url: location.href,
  global: true,
  type: "GET",
  contentType: "application/x-www-form-urlencoded",
  processData: true,
  async: true,
  timeout: 0,
  data: null,
  username: null,
  password: null,
  traditional: false,
  // Create the request object; Microsoft failed to properly
  // implement the XMLHttpRequest in IE7 (can't request local files),
  // so we use the ActiveXObject when it is available
  // This function can be overriden by calling jQuery.ajaxSetup
  xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ?
   function() {
    return new window.XMLHttpRequest();
   } :
   function() {
    try {
     return new window.ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {}
  accepts: {
   xml: "application/xml, text/xml",
   html: "text/html",
   script: "text/javascript, application/javascript",
   json: "application/json, text/javascript",
   text: "text/plain",
   _default: "*/*"

The most important settings are:

  1. url – This property stores the URL used to fetch an Ajax resource. It defaults to the current URI of a web document.
  2. type – This property stores the HTTP method used to fetch an Ajax resource. It defaults to GET.
  3. contentType – This property sets the default content type send with a POST request.
  4. async – This property defines if an Ajax request should be made asynchronously or not. It defaults to true
  5. xhr – This method actually creates the XMLHttpRequest object.
  6. accepts – This object literal stores a list of the content types accepted by jQuery.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.