2013-07-27 71 views
0

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

$。如果在.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

你需要从getReturn()

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

对不起返回由$.post返回的承诺,我不知道该函数是如何比我贴不同... – kylex

+0

@kylex有一个' '$ .post'之前的'return'关键字 –

+0

噢,天啊,错过一件简单的事情。谢谢! – kylex

相关问题