jQuery 3.x 中的 jqXHR 对象是否仍支持 .done 方法?

Will the .done method still be supported for jqXHR objects in jQuery 3.x?

我注意到在我的 JavaScript 代码中,AJAX 请求通常使用以下 jQuery 2.x 模式执行:

$.ajax({
     ...
})
.done(function (data) {
     ...
});

done 方法中找到的代码将在收到响应后执行。

阅读 jQuery 3.x (https://blog.jquery.com/2016/01/14/jquery-3-0-beta-released/) 的测试版发行说明后,我注意到以下声明:

Removed special-case Deferred methods in jQuery.ajax

jqXHR object is a Promise, but also has extra methods like .abort() so that you can stop a request after it has been made.

As users increasingly embrace the Promise pattern for asynchronous work like AJAX, the idea of having special cases for the Promise returned by jQuery.ajax is an increasingly bad idea.

success, error, complete, done, fail, always

Note that this does not have any impact at all on the callbacks of the same name, which continue to exist and are not deprecated. This only affects the Promise methods!

如果我没看错,这似乎表明我在返回响应后执行 JavaScript 代码的方法将不再受支持。是这样吗,还是我遗漏了什么?此外,我是否正确理解 successerror 回调函数现在是执行此类任务的首选方法?

如有任何说明,将不胜感激!

看一下测试版代码,我可以确认

  • done
  • fail
  • always
  • progress
  • state
  • pipe

除了新的 thencatch 方法外,还继续支持其他方法。

在 jqXHR 对象(也是承诺)上,方法 successerrorcomplete(自 1.8 起已弃用)have been removed.