参考:https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API/Using_Fetch
fetch不是Ajax,它诞生的目的是为了代替Ajax,它是js中内置的API。
基于fetch可以实现客户端和服务端的信息通信
由于fetch是2018年提出,因此存在浏览器兼容问题。
fetch('https://v1.hitokoto.cn', {
method: 'GET',
}).then(result => {
console.log(result);
})
fetch('https://v1.hitokoto.cn', {
method: 'POST',
body: 'c=b',
headers: {
'Content-Type': 'x-www-form-urlcoded'
},
credentials: 'include'
}).then(result => {
console.log(result);
})
通过回调函数并不能直接获得响应结果。其返回结果为一个对象。