异步承诺链接
如果你有多个异步任务需要依次发生,则需要将其 promise 对象链接在一起。这是一个简单的例子:
function First() {
console.log("Calling Function First");
return $.get("/ajax/GetFunction/First");
}
function Second() {
console.log("Calling Function Second");
return $.get("/ajax/GetFunction/Second");
}
function Third() {
console.log("Calling Function Third");
return $.get("/ajax/GetFunction/Third");
}
function log(results){
console.log("Result from previous AJAX call: " + results.data);
}
First().done(log)
.then(Second).done(log)
.then(Third).done(log);