1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| var p1 = fetch("https://m.shanghaim.net/api/banner/get1") .then(response => { if (response.status === 200) { return response.json(); } else { throw new Error("Something went wrong on api server!"); } }) .then(e => e) .catch(error => { throw error; }); var p2 = fetch("https://m.shanghaim.net/api/music/top212") .then(response => { if (response.status === 200) { return response.json(); } else { throw new Error("Something went wrong on api server!"); } }) .then(e => e) .catch(error => { throw error; });
Promise.all([p1, p2]) .then(result => { console.log(result); }) .catch(error => { console.log("ERROR " + error); });
|