【发布时间】:2017-11-11 02:09:12
【问题描述】:
我正在尝试调用一些这样的异步函数。为什么案例 A 和案例 B 我失败了,但案例 C 成功了?
案例A
firstCall()// try to get esstential parameters(a defered)
.fail(function(){
//failed :call login function again wait user to input login credential(also a defered)
})
.always(function() {
//show welcome message
})
这种情况下fail刚开始执行,always部分不等待就直接执行。
案例 B
firstCall()// try to get esstential parameters(a defered)
.fail(function(){
//failed :call login function again wait user to input login
})
.done(function() {
//show welcome message
})
在这种情况下,如果失败的部分被执行,但完成的部分永远不会被执行。
案例 C
firstCall()// try to get esstential parameters(a defered)
.then(null,function(){
//failed :call login function again wait user to input login
})
.always(function() {
//show welcome message
})
此时then部分作为fail部分,在then完成后始终可以运行。
我不确定为什么会发生这种情况。有人可以进一步解释吗?谢谢
【问题讨论】:
-
firstCall()返回什么?什么版本的jQuery?
标签: jquery jquery-deferred deferred