Globally configure all $.ajax requests to support retry on timeout

前端 未结 2 1948
北恋
北恋 2021-01-24 08:17

I need a way to set some kind of timeout function globally with $.ajaxSetup that will allow my Phonegap application to keep retrying an ajax GET or POST every time there is a ti

2条回答
  •  感情败类
    2021-01-24 08:59

    Found a solution to make all AJAX calls work with a retry timeout.

    $(document).ajaxError(function (e, xhr, options) {
        if(xhr.status == 0){
            setTimeout(function(){
                console.log('timeout, retry');
                $.ajax(options);
            }, 5000);
        }
    });
    

提交回复
热议问题