我有三个功能。我想在功能二(功能一之后)和功能三完成后做一些事情。我该怎么办?
function one(){
$.ajax({
url:'url'
}).done(function(res){
two();
})
}
function two(){
$.ajax({
url:'url'
})
}
function three(){
$.ajax({
url:'url'
})
}
最佳答案
从每个函数返回 $.ajax
promise ,然后您可以使用 $.when()
function one() {
return $.ajax({
url: 'url'
}).then(two);
}
function two() {
// return request promise
return $.ajax({
url: 'url'
})
}
function three() {
// return request promise
return $.ajax({
url: 'url'
})
}
$.when(one(),three()).then(function(){
//all three requests completed here
})
关于jquery - ajax链式调用完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50382530/