I have many called ajax request from many js file. I want to detect few ajax request to interrupt the execution and execute a newer one. can I detect and stop the ajax with their url?
I would be greatly appreciative of any help I could gain.
I have many called ajax request from many js file. I want to detect few ajax request to interrupt the execution and execute a newer one. can I detect and stop the ajax with their url?
I would be greatly appreciative of any help I could gain.
Here is code adapted from this post. It's untested, but should give the idea. It stuffs the xhr call into an array, along with URL, and then calls them back out to kill them based on URL.
var url = "some.php",
xhr_global = [];
var jqxhr = $.ajax({
type: "POST",
url: url,
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
xhr_global.push({xhr: jqxhr, url: url});
function kill_url(url_pick){
for(var i=0; i<xhr_global.length; i++){
if (xhr_global[i].url == url_pick) // If url matches, kill xhr
xhr_global[i].xhr.abort();
}
}
kill_url("some.php"); // Call function to kill the xhrs
Note that, as the post says, this kills the process on client-side, but not server-side.