how can I cancel an Ajax request?

This question already has an answer here:

  • Abort Ajax requests using jQuery 18 answers
  • How to cancel/abort jQuery AJAX request? 7 answers

  • 嗨它类似于使用jQuery中止Ajax请求,无论如何这可以帮助你

     var ab = $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });
    
    //kill the request
    ab.abort()
    

    将从ajax请求返回的promise界面存储在global variable ,并在取消点击时abort

    var result = $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });
    
    
    $('#cancel').click(function() {
        result.abort();
    });
    

    var request= $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });
    
    
    $('#cancel').click(function() {
        request.abort();
    });
    

    this will abort the request from the client(browser) side but note : if the server has already received the request, it may continue processing the request (depending on the platform of the server) even though the browser is no longer listening for a response. There is no reliable way to make the web server stop processing a request that is in progress.

    链接地址: http://www.djcxy.com/p/71926.html

    上一篇: 如何在jquery中停止Ajax调用

    下一篇: 我如何取消Ajax请求?