解决chrome浏览器跨域请求报Refused to execute script from

          在最近一次项目中有一个接口是JSONP接口,也就是允许跨域访问,在firefox中是可以正常访问,chrome中确报如下错

Refused to execute script from 'xxxxxxxxxx' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

 找了半天才发现因为服务器端框架比较新,在响应头文件中加了如下参数,可以在浏览器调试器的网络中查看到

x-content-type-options:nosniff

这样chrome只能访问响应内容类型为如下的JSONP接口

    "application/ecmascript"
    "application/javascript"
    "application/x-javascript"
    "text/ecmascript"
    "text/javascript"
    "text/jscript"
    "text/x-javascript"
    "text/vbs"
    "text/vbscript"

 那么只能由服务器端修改代码,手动设置内容为如上的一种

	response.setContentType("text/javascript");//如果不这样设置 chrome浏览器无法调用
如果您觉得我的文章给了您帮助,请为我买一杯饮料吧!我将非常感激并坚持为大家提供更多帮助!

猜你喜欢

转载自bewithme.iteye.com/blog/2309855
今日推荐