Search code examples
jqueryajax

Stop all active ajax requests in jQuery


I have a problem, when submitting a form all active ajax request fail, and that triggers error event.

How to stop all active ajax requests in jQuery without trigerring error event?


Solution

  • Every time you create an ajax request you could use a variable to store it:

    var request = $.ajax({
        type: 'POST',
        url: 'someurl',
        success: function(result){}
    });
    

    Then you can abort the request:

    request.abort();
    

    You could use an array keeping track of all pending ajax requests and abort them if necessary.