0
点赞
收藏
分享

微信扫一扫

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


文档:

  • ​​https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API/Using_Fetch​​
  • ​​https://www.ruanyifeng.com/blog/2020/12/fetch-tutorial.html​​

示例

发送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);
})();


举报

相关推荐

0 条评论