开发者

jQuery.Deferred "then" callback giving unexpected behavior

It seems as if the then() callback is not firing when a Deferred object is rejected. It was my understanding then() should be executed whether the Deferred resolves or rejects.

Here is an example (open in a jsFiddle console)

var doDfd = function(input){
    var dfd = $.Deferred();

    if(input == 'fail'){
        dfd.reject();
    }
    else{
        dfd.resolve();
    }     

    return dfd.promise();
}


doDfd('fail')
    .done(function(r){console.log('success')})
    .fail(function(r){console.log('fa开发者_运维百科il')})
    .then(function(r){console.log('then logic')});
​


deferred.then takes two arguments - one is a done callback, the other one is a fail callback (or callbacks because any of those arguments can be an array of functions).

See this fiddle: http://jsfiddle.net/Mrqf8/480/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜