您当前的位置: 首页 >  http

彭世瑜

暂无认证

  • 4浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

彭世瑜 发布时间:2022-09-20 11:24:38 ,浏览量:4

文档:

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

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.2224s