+
95
-

fetch与ajax有什么区别 ?

fetch与ajax有什么区别 ?

网友回复

+
15
-
fetch

fetch是基于promise实现的,也可以结合async/await。

fetch请求默认是不带COOKIE的,需要设置fetch(URL,{credentials:’include’})。Credentials有三种参数:same-origin,include,*

服务器返回400 500 状态码时并不会reject,只有网络出错导致请求不能完成时,fetch才会被reject。

所有版本的 IE 均不支持原生 Fetch。

fetch是widow的一个方法;

fetch比较与ajax有着更好更方便的写法;

var arr1 = [{
    name: "bfw",
}];

    fetch("url", {
        method: "post",
        credentials: 'include',
        headers: {//设置请求的头部信息
            "Content-Type": "application/json",
          
            //跨域时可能要加上
            //"Accept":"allication/json"
        },    //将arr1对象序列化成json字符串
   ...

点击查看剩余70%

我知道答案,我要回答