Sergio TulentsevTom Lehman提出了一个问题:What's the best way to retry an AJAX request on failure using jQuery?,或许与您遇到的问题类似。
Something like this:
$.ajax({
url : 'someurl',
type : 'POST',
data : ....,
tryCount : 0,
retryLimit : 3,
success : function(json) {
//do something
},
error : function(xhr, textStatus, errorThrown ) {
if (textStatus == 'timeout') {
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
//try again
$.ajax(this);
return;
}
return;
}
if (xhr.status == 500) {
//handle error
} else {
//handle error
}
}
});
希望本文对你有帮助,欢迎支持JavaScript中文网