javascript - 禁用 Chrome 严格的 MIME 类型检查

标签 javascript jquery angularjs google-chrome

有没有办法在 Chrome 中禁用严格的 MIME 类型检查

实际上,我正在跨域发出 JSONP 请求。它在 Firefox 上运行良好,但在使用 chrome 时在控制台中出现一些错误。

Refused to execute script from 'https://example.com' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

它在 Mozilla 中完美运行..问题只在 chrome 中出现

这是请求的响应 header ..

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

最佳答案

服务器应该为 JSONP application/javascript 返回正确的 MIME 类型,你的请求应该告诉 jQuery 你正在加载 JSONP dataType: 'jsonp'

请参阅this answer了解更多详情! 您也可以have a look a this one因为它解释了为什么用 text/plain 加载 .js 文件不起作用。

关于javascript - 禁用 Chrome 严格的 MIME 类型检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39228657/

相关文章:

javascript - jQuery .unbind() 方法是否仅适用于 jQuery 创建的事件?

javascript - 导航栏不固定

javascript - 从 JSON 日期到 JS 日期

javascript - javascript中替换文本问题

javascript - AngularJS ngTable 中每行的按钮

javascript - 谷歌折线图将 float 转换为整数

javascript - JS 异步函数循环

javascript - 本地存储: Get specific localstorage value of which contains many items

javascript - SortBy 排序不正确?

javascript - AngularJS 与 ReactJS