How do I chain a sequence of deferred functions in jQuery 1.8.x?

后端 未结 2 1199
逝去的感伤
逝去的感伤 2020-12-14 18:29

Given these functions:

function func1() {
  var dfd = $.Deferred();

  setTimeout(function() {
    dfd.resolve(\'Password\');
  }, 1000);

  return dfd.promi         


        
2条回答
  •  借酒劲吻你
    2020-12-14 19:00

    It's not that complicated (either use .then or .pipe, they are both the same since jQuery 1.8 I think).

    func1().then(func2).done(function(message) {
        alert(message);
    });
    

    Since func2 returns a new deferred object, the .done callback is attached to that one instead.

    DEMO

提交回复
热议问题