Вопрос по ajax, jquery – Остановить $ .ajax перед отправкой
У меня есть этот вызов jQuery ajax:
<code>$.ajax({ url : 'my_action', dataType: 'script', beforeSend : function(){ if(1 == 1) //just an example { return false } }, complete: function(){ console.log('DONE'); } }); </code>
Я хочу остановить вызов AJAX подbeforeSend
если условие возвращаетсяtrue
но возвращение false не останавливает вызов ajax.
Как я могуstop
вызов Аякса наbeforeSend
?
======= ОБНОВЛЕНИЕ =========
return false
работает так же.
Возможный дубликатstackoverflow.com/questions/446594/…
4
ответа
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(xhr, opts){
if(1 == 1) //just an example
{
xhr.abort();
}
},
complete: function(){
console.log('DONE');
}
});
Error: User Rate Limit Exceeded
$(document).on("ajax:beforeSend", ".my-selector", function(e, xhr) { … })
Error: User Rate Limit Exceededxhr
Error: User Rate Limit Exceeded
xhr.done()
;
this works for me
$. 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 ) {});
Альтернативная конструкция для опции обратного вызова успеха, обратитесь кdeferred.done()
для реализации деталей.
Похожие вопросы
Возможный дубликат<a href="http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery" title="kill ajax requests using javascript using jquery">stackoverflow.com/questions/446594/…</a>