我想得到一个api,然后再打电话给另一个.在javascript中明智地使用这样的代码吗?
fetch(url, {
method: 'get',
}).then(function(response) {
response.json().then(function(data) {
fetch(anotherUrl).then(function(response) {
return response.json();
}).catch(function() {
console.log("Booo");
});
});
})
.catch(function(error) {
console.log('Request failed', error)
});
Run Code Online (Sandbox Code Playgroud)