ajax-返回并防止延迟.then()执行
ajax - return and prevent deferred.then() execution
我有一个AJAX请求,如下所示:
$.ajax({
type: 'GET',
url: url,
dataType: "json",
success: function(data) {
// ...
callbak(true);
},
})
.then(
function( response ) {
// ...
});
我想运行那个回调函数,从而退出success
函数中的ajax请求,并阻止执行deferred.then()
。在我的情况下,callback
被激发,但之后deferred.then()
也被执行,我不希望这种情况发生。
知道吗?
感谢
使用这样的标志:
var executeThen = true;
$.ajax({
type: 'GET',
url: url,
dataType: "json",
success: function(data) {
// ...
executeThen = false;
callbak(true);
},
})
.then(function(response) {
if(executeThen){
// ...
}
});
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- JavaScript执行暂时挂起页面
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 当js函数's已执行
- 哪个先执行
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- HTML表单提交时未执行外部函数
- 如何重写这段代码,使执行不必从Javascript Promise.then()方法开始
- ajax-返回并防止延迟.then()执行
- 类似于jQuery when/then的东西:带break的延迟执行
- 正在从.then()函数执行命名的“胖箭头”
- 基本if/then JS/JQuery-为什么这似乎忽略了if并执行了两次
- 的承诺.在执行.then()之前不等待解析
- 在触发单个函数之前,等待所有.then()执行完毕
- 我需要把'return'casper.then'块,让父函数等待子函数完成执行
- 当我需要调用者的执行暂停/等待时,如何使用promise.then() ?
- 为什么Mocha不执行.then语句中的测试?
- Promises是调用`.then`后执行副作用所需的A+Promises吗
- nodejs then() 函数在 promise 解析之前执行
- 链式jQuery.then() -每个下一个只在前一个解析完成后执行