gpt4 book ai didi

javascript - 4-5 Ajax 调用成功后调用 javascript 函数

转载 作者:行者123 更新时间:2023-11-28 19:41:21 26 4
gpt4 key购买 nike

我需要进行 4-5 个 Ajax 调用,一旦所有这些调用都成功,我需要调用 JavaScript 函数。我正在使用ExtJS。我也可以使用 JQuery 进行这些 Ajax 调用。

一旦所有这些 Ajax 调用都成功,我如何调用函数。

我可以创建 4-5 个标志,并且每次 ajax 调用成功时,我会将相应的标志设置为 true,一旦所有标志都为 true,我将进行函数调用。

有没有更好的方法来达到预期的结果。

最佳答案

您可以使用 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/

关于javascript - 4-5 Ajax 调用成功后调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24956973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com