I have this jQuery ajax call:
$.ajax({
url : \'my_action\',
dataType: \'script\',
beforeSend : function(){
if(1 == 1) //just an example
beforeSend:function(jqXHR,setting)
{
// if(setting.url != "your url") jqXHR.abort();
if(1 == 1) //just an example
{
jqXHR.abort();
}
}
xhr.done()
;
this works for me
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(xhr){
if(1 == 1) //just an example
{
return false
};
xhr.done(); //this works for me
},
complete: function(){
console.log('DONE');
}
});
http://api.jquery.com/jquery.ajax/
jqXHR.done(function( data, textStatus, jqXHR ) {});
An alternative construct to the success callback option, refer to deferred.done()
for implementation details.
Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort().
var test = $.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(){
if(1 == 1) //just an example
{
test.abort();
return false
}
},
complete: function(){
console.log('DONE');
}
});
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(xhr, opts){
if(1 == 1) //just an example
{
xhr.abort();
}
},
complete: function(){
console.log('DONE');
}
});