0

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.

Kumal
  • 49
  • 2
  • 9
  • Can you let us know, on which line it is showing/giving undefined error? – Rajiv Ranjan Sep 06 '13 at 11:34
  • 1
    Try one solution: create a js file with one line of code jQuery= jQuery.noConflict(); and add this file on top. And I am assuming you have already added jQuery library. – Rajiv Ranjan Sep 06 '13 at 11:54
  • Uncaught reference error in (jquery) i.e last line of code. I am using master and content pages. I noticed one strange behavior ,when placing the code in master it works in i.e (with error) .Placing the code on master page make this run on google(with error.) .I am also using 1.8.3 min.js in content page. Do I am missing something in code or placing the code in wrong position. I tried your solution now showing same error on newly created js file – Kumal Sep 06 '13 at 12:04

0 Answers0