Stop all active ajax requests in jQuery

前端 未结 16 1111
自闭症患者
自闭症患者 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:28

    var Request = {
        List: [],
        AbortAll: function () {
            var _self = this;
            $.each(_self.List, (i, v) => {
                v.abort();
            });
        }
    }
    var settings = {
        "url": "http://localhost",
        success: function (resp) {
            console.log(resp)
        }
    }
    
    Request.List.push($.ajax(settings));
    

    whenever you want to abort all the ajax request, you just need call this line

    Request.AbortAll()
    

提交回复
热议问题