小编Mon*_*a92的帖子

在javascript中使用另一个fetch中的fetch

我想得到一个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)

javascript fetch-api

29
推荐指数
3
解决办法
3万
查看次数

标签 统计

fetch-api ×1

javascript ×1