Stop all active ajax requests in jQuery

前端 未结 16 919
自闭症患者
自闭症患者 2020-11-22 13:51

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 trigerri

16条回答
  •  花落未央
    2020-11-22 14:35

    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.

提交回复
热议问题