在页面加载时,我使用 jQuery .ajax 函数发送一个 AJAX。在我得到响应后,我想发送另一个 ajax 请求,它将是递归的。
因此,在获得先前的 ajax 请求的响应后,我想发送另一个请求。
在页面加载时,我使用 jQuery .ajax 函数发送一个 AJAX。在我得到响应后,我想发送另一个 ajax 请求,它将是递归的。
因此,在获得先前的 ajax 请求的响应后,我想发送另一个请求。
在这里我试着给你一个样本
function recursiveAjax(url, method, dataType, ) {
$.ajax({
url: url,
method: method,
dataType: dataType,
success: function(response) { // success function call after a successful response
if(response) {
recursiveAjax('script_url', 'POST', 'json');
}
}
})
}
初始调用:
recursiveAjax('script_url', 'POST', 'json');
阅读更多关于$ .ajaxsuccess()
和complete()
方法的信息。
您还可以使用.done()
如下方法:
function recursiveAjax() {
$.ajax({
url: url,
method: method,
dataType: dataType
}).done(function ( response ) {
if(response) {
recursiveAjax(...);
}
});
}
参考jQuery 文档complete
中的orsuccess
参数