10Jan

How to stop an ajax request

[js]

// Perform a simple Ajax request
var req = $.ajax({
type: "GET",
url: "/user/list/",
success: function(data) {
// Do something with the data…
// Then remove the request.
req = null;
}
});

// Wait for 5 seconds
setTimeout(function(){
// If the request is still running, abort it.
if ( req ) req.abort();
}, 5000);
[/js]

Leave a Reply