Reputation: 17074
Is there any way to terminate ajax execution, based on beforeSend result ?
$.ajaxSetup({
beforeSend: check,
});
function check() {
if(success) { /* break ajax execution */ }
else { /* continue */ }
}
Upvotes: 2
Views: 5621
Reputation: 17074
I see that answer can be found here: Stop $.ajax on beforeSend. It should look like below:
$.ajaxSetup({
beforeSend: check,
});
function check(xhr) {
if(success) { xhr.abort(); }
else { /* continue */ }
}
Upvotes: 2
Reputation: 295
Just place it inside a function:
$.ajax({
beforeSend: function() {
check();
},
});
Upvotes: -1
Reputation: 2086
You can try with the abort() method:
var xhr = $.ajax({
type: "POST",
url: "test",
data: "thedata",
success: function(msg){ alert( "Back again: " + msg ); } });
//kill the request... try these on beforeSend
xhr.abort()
Upvotes: 0