I am facing undefined error when user navigates to other link. I am firing 6-7 jquery on page load it works fine on load. When user continous refresh the page or click on other link it showing error. I think this error bcoz of previous request is not completed. I looked on internet and find this useful trick
// Automatically cancel unfinished ajax requests
// when the user navigates elsewhere.
(function($) {
var xhrPool = [];
$(document).ajaxSend(function(e, jqXHR, options){
xhrPool.push(jqXHR);
});
$(document).ajaxComplete(function(e, jqXHR, options) {
xhrPool = $.grep(xhrPool, function(x){return x!=jqXHR});
});
var abort = function() {
$.each(xhrPool, function(idx, jqXHR) {
jqXHR.abort();
});
};
var oldbeforeunload = window.onbeforeunload;
window.onbeforeunload = function() {
var r = oldbeforeunload ? oldbeforeunload() : undefined;
if (r == undefined) {
// only cancel requests if there is no prompt to stay on the page
// if there is a prompt, it will likely give the requests enough time to finish
abort();
}
return r;
}
})(jQuery);
from http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery
it's working fine in google chrome and Opera but not working in internet explorer and mozilla. Can anybody tell me how can i change this code to support all browser.