我需要进行4-5个Ajax调用,一旦所有这些调用都成功,我需要调用一个JavaScript函数。我正在使用ExtJS。我也可以使用JQuery进行这些Ajax调用。
在所有这些Ajax调用都成功之后,我如何调用一个函数。
我可以创建4-5个标志&每次ajax调用成功时,我都会将各自的标志设置为true &一旦所有标志都为true,我就会进行函数调用。
有没有更好的方法来达到预期的效果。
发布于 2014-07-25 21:49:22
您可以使用jQuery when
$.when(
// Get first
$.get("/first/", function(result) {
//Do something with result
}),
// Get second
$.get("/second/", function(result) {
//Do something with result
}),
// Get third
$.get("/third/", function(result) {
//Do something with result
})
).then(function() {
// All is ready now, so...
});来源:http://css-tricks.com/multiple-simultaneous-ajax-requests-one-callback-jquery/
它也被记录在jquery站点上:http://api.jquery.com/jquery.when/
https://stackoverflow.com/questions/24956973
复制相似问题