반응형
보내기 전에 $.ajax를 중지
jQuery ajax 콜이 있습니다.
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(){
if(1 == 1) //just an example
{
return false
}
},
complete: function(){
console.log('DONE');
}
});
Ajax 콜을 중지하고 싶다.beforeSend
상태가 회복되면true
그러나 false를 반환해도 Ajax 콜은 정지되지 않습니다.
제가 어떻게.stop
에 대한 아약스 호출beforeSend
?
======= 업데이트 =========
return false
동작합니다.
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : function(xhr, opts){
if(1 == 1) //just an example
{
xhr.abort();
}
},
complete: function(){
console.log('DONE');
}
});
대부분의 jQuery Ajax 메서드는 XMLHttpRequest(또는 동등한) 개체를 반환하므로 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');
}
});
beforeSend:function(jqXHR,setting)
{
// if(setting.url != "your url") jqXHR.abort();
if(1 == 1) //just an example
{
jqXHR.abort();
}
}
xhr.done()
이것은 나에게 효과가 있다.
$.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 ) {});
성공 콜백옵션의 대체 구성.를 참조해 주세요.deferred.done()
를 참조해 주세요.
언급URL : https://stackoverflow.com/questions/10507079/stop-ajax-on-beforesend
반응형
'programing' 카테고리의 다른 글
사용자 지정 포트에 Wordpress 다중 사이트(네트워크)를 설치할 수 없음 (0) | 2023.03.19 |
---|---|
체크아웃 후 주문 데이터 가져오기 (0) | 2023.03.19 |
콜 앵귤러문서 준비 완료 시 JS 함수 (0) | 2023.03.19 |
Angular.js는 컨트롤러를 앱 네임스페이스로 정리합니다. (0) | 2023.03.19 |
IE에서 "SCRIPT5: Access is denied" 오류 방지 (0) | 2023.03.19 |