我正在尝试使用jQuery获取外部URL的元数据,并通过以下示例链接对其进行了测试 theguardian.com
我希望能够获得精选图片或缩略图链接,以便将其嵌入到我的网站中。
但是我不断收到这个错误
XMLHttpRequest无法加载https://www.theguardian.com/us-news/2016/jul/05/fbi-no-charges-hillary-clinton-email-investigation?format=json。所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问源' http:// localhost:63342 '。
这是我的代码
$.ajax({
type: 'GET',
dataType: 'json',
data: {
format: 'json'
},
url: 'https://www.theguardian.com/us-news/2016/jul/05/fbi-no-charges-hillary-clinton-email-investigation',
error: function() {
console.log('there is an error');
},
success: function(data) {
console.log(data);
}
});
我什至尝试$.get()
得到相同的错误。
看起来theguardian.com不允许来自浏览器的外部请求(必须明确允许)。它可能在浏览器之外工作。查看有关CORS的信息(您遇到的错误):https : //developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句