javascript Ajax重试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Ajax重试相关的知识,希望对你有一定的参考价值。


$.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 Ajax重试的主要内容,如果未能解决你的问题,请参考以下文章

使用递归重试 vue 资源 ajax 调用

在 vuejs 中重试失败的 ajax 请求

成功ajax重试后没有.done

使用 jQuery 在失败时重试 AJAX 请求的最佳方法是啥?

javascript Axios重试

javascript Axios重试