继续踩坑![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/676ebda4729556d2ae74a2569eb85a7a.gif)
![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/676ebda4729556d2ae74a2569eb85a7a.gif)
![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/676ebda4729556d2ae74a2569eb85a7a.gif)
![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/676ebda4729556d2ae74a2569eb85a7a.gif)
![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/676ebda4729556d2ae74a2569eb85a7a.gif)
如题,不多说。When responseType is set to json, then response.data is undefined (only in IE9)
ps:我用的是vue axios
方案一:(亲测有效)
在axios 中千万不要写,否则后果自负
。当然如果这种方案出现了其他问题(目前没有发现),可以试试第二种。
![在IE9下,当responseType设置为json, <wbr>response.data为undefined 在IE9下,当responseType设置为json, <wbr>response.data为undefined](https://i-blog.csdnimg.cn/blog_migrate/aa8e72a08d82be09ef90ccd62c296d3f.gif)
axios.defaults.responseType = 'json'
方案二:
在axios的响应头中设置就好啦~~~
axios.interceptors.response.use( response => {
// IE 8-9
if (response.data == null && response.config.responseType === 'json' &&response.request.responseText != null) {
try {
// eslint-disable-next-line no-param-reassign
response.data = JSON.parse(response.request.responseText);
} catch (e) {
// ignored
}
}
return response;
})