Error Handling and Recovery with jQuery Deferred

半城伤御伤魂 提交于 2019-12-05 13:33:42

No, you cannot use .fail for that. However, you don't need to pass a function as the first argument to .then:

the arguments can be null if no callback of that type is desired.

Since only then enables chaining, you should use

asyncThatWillFail().then(null, function () {
    console.log("error");
    return $.Deferred().resolve();
}).then(function () {
    console.log("continuing on success chain");
});

Apart from the need to return a fulfilled jQuery promise, this is just like the ES6 then method where catch is a synonym for .then(null, …).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!