禁用 Chrome 严格的 MIME 类型检查 [英] Disable Chrome strict MIME type checking

查看:115
本文介绍了禁用 Chrome 严格的 MIME 类型检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在 Chrome 中禁用 严格的 MIME 类型检查.

Is there any way to disable strict MIME type checking in Chrome.

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

Actually I'm making a JSONP request on cross domain. Its working fine on Firefox but, while using chrome its giving some error in console.

拒绝执行来自 'https://example.com' 的脚本,因为它的 MIME 类型 ('text/plain') 不可执行,并且启用了严格的 MIME 类型检查.

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 中出现

Its working perfectly in Mozilla.. Issue is arising in chrome only

这里是请求的响应头..

Here are the response Headers of the request..

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

我认为的解决方法:外部设置 content-type 为 application/javascript

Workaround what i think : Externally setting content-type to application/javascript

推荐答案

服务器应该以正确的 MIME 类型来响应 JSONP application/javascript 并且你的请求应该告诉 jQuery 你正在加载 JSONP 数据类型:'jsonp'

The server should respond with the correct MIME Type for JSONP application/javascript and your request should tell jQuery you are loading JSONP dataType: 'jsonp'

请参阅这个答案 了解更多详情!你也可以看看这个,因为它解释了为什么用<加载.js文件code>text/plain 不起作用.

Please see this answer for further details ! You can also have a look a this one as it explains why loading .js file with text/plain won't work.

这篇关于禁用 Chrome 严格的 MIME 类型检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆