【发布时间】:2018-05-19 21:40:06
【问题描述】:
我一直在谷歌上搜索这个,但我很困惑。我正在尝试使用来自此 api 的数据
https://github.com/artsmia/collection/blob/master/objects/0/1.json
我正在尝试使用 JSONP,因为如果我不这样做会出现跨域错误...这就是我得到的...
function foo(data) {
var parsedData = JSON.parse(data.responseText);
console.log(parsedData.artist);
}
var script = document.createElement('script');
script.src = 'https://github.com/artsmia/collection/blob/master/objects/0/1.json';
document.getElementsByTagName('head')[0].appendChild(script);
foo(script);
但这不起作用。我想这是因为我没有正确链接它,但我不知道如何。
【问题讨论】:
-
只有在 API 有 JSONP 端点时才能使用 JSONP。除非服务器为您提供 JSONP 服务,否则无法获取它
标签: javascript json api jsonp