全局配置所有 $.ajax 请求,支持超时重试 [英] Globally configure all $.ajax requests to support retry on timeout
本文介绍了全局配置所有 $.ajax 请求,支持超时重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一种使用 $.ajaxSetup 全局设置某种超时功能的方法,这将允许我的 Phonegap 应用程序在每次由于互联网连接不良而超时时继续重试 ajax GET 或 POST.
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 timeout due to a bad internet connection.
我使用 Backbone.js,所以大多数 jquery 插件都不能用于此,我会帮助编写一段处理重试的全局代码.
I use Backbone.js so most jquery plugins won't work for this, I would some help writing one global piece of code which will handle retries.
谢谢.
推荐答案
找到了一个解决方案,使所有 AJAX 调用都可以使用重试超时.
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);
}
});
这篇关于全局配置所有 $.ajax 请求,支持超时重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文