tsds
tsds

Reputation: 9010

How to stop ajax request

I'm using jquery for making ajax requests

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

How can I manually stop my particular ajax request?

Upvotes: 6

Views: 16376

Answers (2)

JIA
JIA

Reputation: 1495

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.

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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();

Upvotes: 22

Related Questions