通過$.ajax跨域請求 chrome提示 Uncaught SyntaxError: Unexpected token這是我失敗的代碼 $.ajax({ type: "get", url: "http://open.douyucdn.cn/api/RoomApi/live/lol",
dataType: "jsonp", jsonp: "callback", jsonpCallback: "data", success: function(response) {
console.log(response);
}
});斗魚TV API文檔我去google后,了解到返回的數據是json格式,但我如果將dataType的value改成json后,又會出現跨域問題。這期間我嘗試使用script直接調用該鏈接,但還是同樣的問題,貼出失敗的代碼:var url = "http://open.douyucdn.cn/api/RoomApi/live/lol"; var script = document.createElement("script");
script.setAttribute("src", url); document.getElementsByTagName("head")[0].appendChild(script);我覺得我的問題應該歸納為:如何使用javascript在跨域條件下調用json格式數據?希望大家能指導我一下,謝謝!這個問題來源于freecodecamp上的一個小題目,題目地址我只是將其中的twitch API改為斗魚API
怎樣通過$.ajax跨域請求斗魚TV API 取得json數據
婷婷同學_
2018-10-17 16:15:49