文档:
- 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);
})();