在這個片段中,$。阿賈克斯(本)之後,我需要的是使五種Ajax調用,但我需要每個請求之間的五個秒的延遲。請幫忙!重試Ajax調用錯誤5秒
$.ajax({
type: "POST",
data: JSON.stringify(download),
contentType: "application/json",
url: '',
retryCount: 1,
retryLimit: 5,
success: function(data) {
$.ajax({
type: "GET",
url: '',
})
.success(function(data) {
})
.error(function(data) {
})
},
//It has to go into error
error : function(xhr, textStatus, errorThrown) {
this.retryCount++;
if (this.retryCount <= this.retryLimit) {
//try again
$.ajax(this);
return;
} else {
//user comes here After trying in the if loop for 5 times, with each request having five seconds delay. I am not able to keep delay between each request
}
return;
}
});
您曾經考慮過使用的setTimeout爲你的代碼的延遲方面? –
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout –