jQuery $.get then $.get



如何菊花链$.get调用如下:

let data1;
let data2;
$.get(data1URL).done((data) => {
data1 = data;
secondCall();
}).catch(error => console.log(error));
function secondCall() {
$.get(data2URL).done((data) => {
data2 = data;
buildPage();
}).catch(error => console.log(error));
}
function buildPage() {
console.log(data1);
console.log(data2);
}

您可以使用jQuery.when方法。

$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) )
.then( myFunc, myFailure );

https://api.jquery.com/jquery.when/

最新更新