欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  The jqXHR Object(jqXHR 对象)
  
  从jQuery 1.5开始,所有jQuery的Ajax方法都返回一个XMLHTTPRequest对象的超集。这个通过$.get()方法返回的jQuery XHR对象,或“jqXHR,”实现了 Promise 接口,使它拥有 Promise 的所有属性,方法和行为(见Deferred object获取更多信息)。jqXHR.done() (表示成功), jqXHR.fail() (表示错误), 和 jqXHR.always() (表示完成, 无论是成功或错误) 方法接受一个函数参数,用来请求终止时被调用。关于这个函数接收参数的详细信息,请参阅 jqXHR Object 文档中的 $.ajax() 章节。
  
  Promise 接口也允许jQuery的Ajax方法, 包括 $.get(), 在一个单独的请求中关联到 .done(), .fail(), 和 .always() 回调函数, 甚至允许你在请求已经结束后,指派回调函数。如果该请求已经完成,则回调函数会被立刻调用。
  
  // Assign handlers immediately after making the request,
  
  // and remember the jqxhr object for this request
  
  var jqxhr = $.post("example.php", function() {
  
  alert("success");
  
  })
  
  .success(function() { alert("second success"); })
  
  .error(function() { alert("error"); })
  
  .complete(function() { alert("complete"); });
  
  // perform other work here ...
  
  // Set another completion function for the request above
  
  jqxhr.complete(function(){ alert("second complete"); });
  
  Deprecation Notice(推荐使用的注意事项:)
  
  jqXHR.success(), jqXHR.error(), 和 jqXHR.complete() 回调方法 在jQuery 1.5中引进, 在jQuery 1.8中不赞成使用,已经过时。他们最终将被取消(移除),你的代码应该为次做好准备,使用 jqXHR.done(), jqXHR.fail(), 和 jqXHR.always() 代替.

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h63991.shtml