js:fetch在浏览器中发送 HTTP 请求

文档:

示例

发送GET请求

fetch("http://httpbin.org/get")
    .then(function (response) {
    
    
      return response.json();
    })
    .then(function (data) {
    
    
      console.log(data);
    });

async/await写法

(async function () {
    
    
  const res = await fetch("http://httpbin.org/get");
  const data = await res.json();
  console.log(data);
})();

猜你喜欢

转载自blog.csdn.net/mouday/article/details/126949844