今天给前端童鞋提供一个数据接口, 所有浏览器测试通过丝毫没有问题,最后到了IE9, 报错了。。。打印了错误信息:
Error:拒绝访问, 为啥啊,先网上搜一下吧,大多数是设置一下浏览器internet选项, 照做了,还是一样,
最后找到了问题, ie9 前端后端 需要 设置 编码一致, 那就都指定一下吧,
后端接口 加上这行
header('Content-Type:text/html;charset=utf-8');
前端也加上,这里顺便说一下,还要多加一行:
jQuery.support.cors=true;
$.ajax({ url: 'http://xxx.xxx.xxx/api/xxx/xxx', type: 'GET', cache:false, contentType:'application/json;charset=utf-8', dataType: 'json', data: {}, }) .done(function(res) { console.log(res); }) .fail(function() { console.log("error"); })
cache:false, contentType:'application/json;charset=utf-8',
重点已标红。