jQuery $ .when在完成之前触发

时间:2013-07-27 06:08:16

标签: jquery

我有以下代码无效。

$。当在.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');
});

1 个答案:

答案 0 :(得分:4)

您需要从$.post

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