2016-08-30 334 views
18

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

其实我正在一个跨域的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

+0

你见过这个类似的问题吗? http://stackoverflow.com/questions/17341122/link-and-execute-external-javascript-file-hosted-on-github –

+0

@Rory McCrossan是的...那个问题是指从github中获取文件..而他们是替代解决方法将文件导出为zip .. –

+0

您以纯文本形式发送的内容是什么? –

回答

5

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

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

0

在我的情况下,我关闭X-Content-Type-Optionsnginx然后工作正常。

# Not work 
add_header X-Content-Type-Options nosniff; 
# OK (comment out) 
#add_header X-Content-Type-Options nosniff; 

这对apache也是一样。

<IfModule mod_headers.c> 
    #Header set X-Content-Type-Options nosniff 
</IfModule> 
相关问题