0

我有以下无法正常工作的代码。

$.when,在动作完成之前很久就立即返回.done。如何将操作推迟到.done完成?

var getReturn = function() {
  $.post("/app/return.php", { auth: auth })
  .done(function(data) {
      // Does some calculations, does not return values 
  }); 
} 

$.when(getReturn())
.done(function(response1) {
   console.log('fire');
});
4

1 回答 1

4

您需要返回$.postfrom返回的承诺getReturn()

var getReturn = function() {
    return $.post("/app/return.php", { auth: auth })
    .done(function(data) {
        // Does some calculations, does not return values 
    }); 
}
于 2013-07-27T06:10:41.840 回答