gpt4 book ai didi

ajax - jQuery $.post 可以从回调中再次调用自身吗?

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

用例是,如果它得到的响应不是它想要的,它可以再次调用自己。

$.post(qrLoginAjax.ajaxurl, { 
userID : '11234324'
},function( response ) {
if (response.userID != 'undefined'){
//do stuff
} else {
// call $.post again
}
});

我该怎么做?

谢谢

最佳答案

你可以这样做:

var sendAjax = function() {
$.post('/foo', function(result) {
if (response.userID != 'undefined') {
// do stuff
} else {
// resend the AJAX request by calling the sendAjax function again
sendAjax();
}
});
};

sendAjax();

但在我看来,发送这样的 AJAX 请求似乎是一个糟糕的设计决策。您应该确保不会通过使用重试次数计数器等方式陷入无限递归。

关于ajax - jQuery $.post 可以从回调中再次调用自身吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8957630/

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