« Back to Index

cancel all jQuery AJAX requests

View original Gist on GitHub

Tags: #js

cancelAJAX.js

$.xhrPool = [];

$.xhrPool.abortAll = function() {
  /* Original example used _underscore api
    _.each(this, function(jqXHR) {
        jqXHR.abort();
    });
  */
    $.each(this, function(jqXHR) { 
        jqXHR.abort(); 
    });
};

$.ajaxSetup({
    beforeSend: function(jqXHR) {
        $.xhrPool.push(jqXHR);
    }
});