我已经知道如何检测所有AJAX进程是否由以下代码完成:
jQuery(document).ajaxStop(function(){
alert('All AJAX Process is done.');
});
例如,有三个AJAX流程:oneProcess
,twoProcess
,threeProcess
。
oneProcess
和twoProcess
已经完成,threeProcess
仍在处理中。我是如何调用两个AJAX进程完成的?
答案 0 :(得分:1)
最简单的方法是使用# Nicely end the program
li $v0, 0
jr $ra
,将# Nicely end the program
li $v0, 10
syscall
,$.when()
作为参数传递。
oneProcess
twoProcess
或者,您可以利用var oneProcess = new $.Deferred(function(dfd) {
setTimeout(function() {
dfd.resolve("oneProcess complete")
}, Math.floor(Math.random() * 1500));
return dfd.promise()
}).then(log);
var twoProcess = new $.Deferred(function(dfd) {
setTimeout(function() {
dfd.resolve("twoProcess complete")
}, Math.floor(Math.random() * 1500));
return dfd.promise()
}).then(log);
var threeProcess = function(msg) {
log(msg);
return new $.Deferred(function(dfd) {
setTimeout(function() {
dfd.resolve("threeProcess complete")
}, Math.floor(Math.random() * 1500));
return dfd.promise()
})
}
function log(msg) {
console.log(msg);
}
var checkOneTwo = $.when(oneProcess, twoProcess);
checkOneTwo.then(function(one, two) {
threeProcess(
"oneProcess state:" + oneProcess.state()
+ ", twoProcess state:" + twoProcess.state()
).then(log)
});
在每个延期对象上调用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
来检查setInterval
,.state()
oneProcess
次来电twoProcess
}。
deferred.state()
"resolved"