gpt4 book ai didi

jquery - 如何为多个ajax请求设置 "success"函数?

转载 作者:行者123 更新时间:2023-12-01 01:29:09 25 4
gpt4 key购买 nike

如何为所有已完成的请求设置 ajax success

$.ajax({
success: function(){ clicked = false;}
});

$('.button').click(function(){
$.post('file.php',{},function(){});
$.post('file.php',{},function(){});
$.post('file.php',{},function(){});
});

最佳答案

您的意思是在所有请求完成后执行一个方法吗?

var counter = 0;
var nRequests = 3;

function multiSuccess() {
// do something
}

$('.button').click(function(){
$.post('file.php',{},function(){
counter++;
if(counter == nRequests) {
multiSuccess();
}
});
$.post(...
$.post(...
});

此外,您可能想查看 ajaxStop :

Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event. Any and all handlers that have been registered with the .ajaxStop() method are executed at this time.

关于jquery - 如何为多个ajax请求设置 "success"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4768898/

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