Cancel pending AJAX requests in PHP app?

前端 未结 3 1876
醉酒成梦
醉酒成梦 2021-01-07 23:53

I\'m having problems canceling my XHR requests when navigating between pages. I have a page that has 8 requests that get fired off. I cancel them on click of a link outside

3条回答
  •  伪装坚强ぢ
    2021-01-08 00:37

    Are you storing your Ajax Request on a variable?. If not, that's what you need to do to completely cancel a request

    var xhr = $.ajax({
        type: "POST",
        url: "anyScript.php",
        data: "data1=0&data2=1",
        success: function(msg){
           //Success Function
        }
    });
    
    //here you abort the request
    xhr.abort()
    

提交回复
热议问题