[英]Why is .getJSON function returning MIME type error from API
我一直在嘗試從Forismatic API調用 ,但是在發送時返回了MIME類型錯誤。
jQuery請求:
$(document).ready(function() {
$("#quote-button").on("click", function(){
$.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en", function(json) {
$(".quote-text").html(JSON.stringify(quoteText));
});
});
});
錯誤信息
拒絕執行來自' https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en&jsonp=jQuery32104928506782842177_1494780473751&_=1494780473752 '的腳本,因為其MIME類型('application / json')不可執行且嚴格MIME類型檢查已啟用。
我看過添加callback=?
並改為https
而不是http
,但是它們沒有用。
根據API文檔,您需要將格式設置為"jsonp"
並設置jsonp
參數:
$.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?", function(json) { console.log(json) })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.