3
我有三個API網址,每個網址都有相同的對象名稱,我希望同時調用所有API。調用多個API網址並同時呼叫
我的JS至今:
$(document).ready(function() {
var first = 'https:first';
var second = 'https://second';
var third = 'https://third';
$('#get-data').click(function() {
var showData = $('#show-data');
$.getJSON(first,second,third function(data) {
showData.empty();
var items = data.map(function(elem) {
return $("<li />", {
text: elem.title
});
});
var list = $('<ul />').append(items);
showData.append(list);
});
});
});
看看'Promise.all'! – funcoding
謝謝你生病了看看這個 – Beep
沒問題。我的例子會是這樣的:'Promise.all([$ .getJSON(first),$ .getJSON(second),$ .getJSON(third)])。then(function(values){// do something}) ' – funcoding