小编典典

禁用Chrome严格的MIME类型检查

angularjs

有什么方法可以strict MIME type checking在Chrome中禁用。

实际上,我正在跨域发出JSONP请求。它可以在Firefox上正常工作,但是在使用chrome时,在控制台上会出现一些错误。

拒绝从“ https://example.com ” 执行脚本,因为其MIME类型(“ text /
plain”)不可执行,并且启用了严格的MIME类型检查。

它在Mozilla中可完美运行。问题仅在Chrome中出现

这是请求的响应标头。

Cache-Control:no-cache, no-store
Connection:Keep-Alive
Content-Length:29303
Content-Type:text/plain;charset=ISO-8859-1
Date: xxxx
Expires:-1
Keep-Alive:timeout=5
max-age:Thu, 01 Jan 1970 00:00:00 GMT
pragma:no-cache
Set-Cookie:xxxx
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN

解决方法,我认为 :外部设置内容类型为application/javascript


阅读 907

收藏
2020-07-04

共1个答案

小编典典

服务器应使用JSONP的正确MIME类型进行响应,application/javascript并且您的请求应告诉jQuery您正在加载JSONPdataType:'jsonp'

请参阅此答案以获取更多详细信息!您也可以看看这个,因为它解释了为什么无法使用加载.js文件text/plain

2020-07-04