Fetch API

309 阅读1分钟
  • fetch就是一个基于promise语法的函数,响应成功后会返回一个promise。
  • 示例
<script>
    fetch('https://www.xxx.com/',{
        method: 'post',
        //转换为JSON格式
        body: JSON.stringify({key: value}),
        headers: {
            'Content-Type': 'application/json'
        }
    }).then(res => { res.json() }).then(data => {console.log(data)})
</script>