2016-08-30 156 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> 
相關問題