ajaxSettings

Home文章
 简介:ajaxSettings是用来处理一个Ajax连接的所有细节jQuery的私有类。

ajaxSettings是用来处理一个Ajax连接的所有细节jQuery的私有类。

细节如下:

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: "*/*"
 }
 }

 

 

重要的部分:

  1. url – 提交到的url,默认当前页.
  2. type – 提交方式,默认GET.
  3. contentType – This property sets the default content type send with a POST request.
  4. async – ajax请求是否异步. 默认true,异步
  5. xhr – 实例化一个异步对象
  6. accepts – This object literal stores a list of the content types accepted by jQuery.

 

翻译自:http://onwebdev.blogspot.com/2010/06/jquery-unveiled-ajaxsettings-class.html



评论
Login