jQuery.getJSON 访问被拒绝
我正在编写一个简单的书签,它在 youtube 页面上运行,并从 youtube api 获取有关当前播放视频的一些数据。
书市在 Chrome 和 Firefox 上运行,但在 IE 上(目前仅在 IE9 上测试),我从下一个代码中收到错误:
jQuery.support.cors = true;
$.getJSON('https://gdata.youtube.com/feeds/api/videos/' + vid + '?v=2&alt=json',YoutubeBookmarklet.handle_gdata_obj)
.error(function(xhr, ajaxOptions, thrownError) {
console.log(thrownError);
});
我得到的第一个错误是“No Transport”,在 stackoverflow 的帮助下,我发现我需要添加jQuery.support.cors = true 为了修复它,添加它后我收到另一个错误:“访问被拒绝。”
我尝试使用 IE XDomainRequest,但我得到同样的错误。
该怎么办?
I am writing a simple bookmarklet that runs on youtube page and fetch some data from the youtube api about the current playing video.
The bookmarket runs on Chrome and Firefox,but on IE(currently tested only on IE9) I am getting error from the next code :
jQuery.support.cors = true;
$.getJSON('https://gdata.youtube.com/feeds/api/videos/' + vid + '?v=2&alt=json',YoutubeBookmarklet.handle_gdata_obj)
.error(function(xhr, ajaxOptions, thrownError) {
console.log(thrownError);
});
The first error I got was "No Transport",by the help of stackoverflow I saw that I need to add jQuery.support.cors = true in order to fix it,after adding it I am getting another error : "Access is denied."
I tried to use the IE XDomainRequest,but I get the same error.
What to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 JSONP 修复了它,为此我添加了“&callback=?”到网址末尾。
I fixed it using JSONP in order to do so i added "&callback=?" to the end of the url.
看起来像是跨域调用,看看这个希望对你有帮助。
http://james.padolsey.com/javascript/cross-domain-请求与 jquery/
Looks like a cross domain call, take a look at this hope it will help you.
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/