How to stop ajax request

后端 未结 2 1714
南笙
南笙 2020-12-19 06:44

I\'m using jquery for making ajax requests

$.ajax(
    url: \"http://someurl.org\",
    success: function() { ... }
);

How can I manually s

相关标签:
2条回答
  • 2020-12-19 06:44

    ajax requests are HTTP transactions once made cannot be stopped. You can stop ajax request from being initiated but not kill the already made request.

    0 讨论(0)
  • 2020-12-19 07:02

    The $.ajax() method returns an object that could be used to do that:

    var xhr = $.ajax(
        url: "http://someurl.org",
        success: function() { ... }
    );
    

    and then later when you want to stop the request:

    xhr.abort();
    
    0 讨论(0)
提交回复
热议问题