Well you might clone the object using jQuery and then restart your call when the browser goes back online
// Deep copy
var savedXhr= jQuery.extend(true, {}, xhr);
不知道这是否真正可行,你可以尝试。
EDIT - Ok i tried it and no way, you can t call send() on that object. This is because xhr
is not the original request but a fake object created by jQuery
A different approach might be this one: You save the settings object and then you start another $.ajax call with
those settings.
Basically you do
var settingsSaved;
$(document).ajaxSend(function(event, xhr, settings, response) {
if (!navigator.onLine) {
settingsSaved = jQuery.extend(true, {}, settings);
xhr.abort();
} else {
//Send the request with the old settings
$.ajax(settingsSaved);
//abort the new request
xhr.abort();
}
}
真正谨慎的是,由于你每次打上美元,你都会触发另一个<条码>瓦克斯·代码>的活动。 XMLHTTPRequest using the Value from the dingsSaved
Object.
Look at this fiddle, the first time you click a button, the call is aborted. The second time the call starts with the old settings and from then on all requests are normal
http://jsfiddle.net/hFmWX/。