jQuery.getJSON 访问被拒绝

发布于 2024-11-27 21:52:42 字数 571 浏览 2 评论 0原文


我正在编写一个简单的书签,它在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜清冷一曲。 2024-12-04 21:52:42

我使用 JSONP 修复了它,为此我添加了“&callback=?”到网址末尾。

I fixed it using JSONP in order to do so i added "&callback=?" to the end of the url.

喜爱纠缠 2024-12-04 21:52:42

看起来像是跨域调用,看看这个希望对你有帮助。

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文