看了github上的fetch-ie8,想用fetch代替ajax,遇到了一些问题
已引入 fetch.js,es6-promise.js,es5-shim.js,es5-sham.js
先贴代码:
fetch($rpUrl+'/inquiry/save',{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: dataCollection,
credentials: "include" //默认不带cookie,增加此参数带cookie
}).then(function (response) {
return response.json(); //这里在IE8没有解析为json
}).then(function (rst) {
console.log(typeof rst); //此处在IE8以上是Object,在IE8是String
},function(e){
});
这是fetch-ie8的,按道理应该是支持IE8的才对
别说把String 转成 json数据,问题是转不了。是不是请求头哪里错了?
猜测fetch的json解析用了JSON.parse,而IE8不支持
你把IE8里错误信息发出来看看?