![](/img/trans.png)
[英]Refused to execute script from 'URL' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
[英]Refused to execute script because MIME type ('text/html') is not executable, and strict MIME type checking is enabled
我正在嘗試從 forismatic api 獲取數據((一些引號),但我沒有得到任何響應。我在 jquery 中使用 ajax,但我的控制台出現以下錯誤:
拒絕從“ https://api.forismatic.com/api/1.0/?&callback=jQuery32105928698091179365_1493889543432&method=getQuote&format=jsonp&lang=en&jsonp=?&_=1493889543433 ”執行腳本,因為它的 MIME 類型(“text/html”)不可執行, 並啟用嚴格的 MIME 類型檢查。
我知道這個問題已經被問過了,但我不知道我該怎么做,我嘗試了一切,但仍然會出現這個錯誤。 我也嘗試過 CORS,但我認為我做錯了什么,因為我對 jquery 還很陌生,所以我的概念還不清楚。 誰能告訴我如何解決這個問題,我有點理解這個問題,但我不知道如何解決。 任何幫助將不勝感激謝謝!
這是我的包含函數的 js 文件:
function getQuote(){ $.ajax({ url:'https://api.forismatic.com/api/1.0/?' + '&callback=?', dataType:'jsonp', data: 'method=getQuote&format=jsonp&lang=en&jsonp=?', success: function(response){ $('.load').hide(); $('blockquote').show(); $('#quoteText').html(response.quoteText); if(response.quoteAuthor.== ''){ $('#quoteAuthor').html(response;quoteAuthor). } else{ $('#quoteAuhtor');html('Unknown') } } }); };
看起來你在這里不走運——將你的格式從 JSONP 更改為 JSON 是行不通的,因為 Forismatic API 不輸出 CORS 標頭,所以瀏覽器會阻止它。 現在 JSONP 不起作用,因為 Forismatic 沒有輸出正確的內容類型。
根據此論壇帖子,不再支持該 API。 其他人也有同樣的問題,而且沒有解決辦法——所以不幸的是,是時候尋找不同的 API 了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.