DIEA
2019-10-24 15:18:29
偽代碼:$(document).ajaxError(function(e, xhr, options, error) { xhr.retry()})更好的是某種指數補償
3 回答

慕仙森
TA貢獻1827條經驗 獲得超8個贊
像這樣:
$.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
}
}
});
添加回答
舉報
0/150
提交
取消