我有这样的AJAX请求:
$.ajax({
type: 'GET',
url: url,
dataType: "json",
success: function(data) {
// ...
callbak(true);
},
})
.then(
function( response ) {
// ...
});
我想运行该回调函数,因此退出success
函数中的ajax请求并阻止deferred.then()
执行。
在我的情况下,callback
被解雇但在此之后deferred.then()
也被执行了,我不希望这种情况发生。
有什么想法吗?
由于
答案 0 :(得分:0)
使用这样的标志:
var executeThen = true;
$.ajax({
type: 'GET',
url: url,
dataType: "json",
success: function(data) {
// ...
executeThen = false;
callbak(true);
},
})
.then(function(response) {
if(executeThen){
// ...
}
});