即使请求的 URL 工作正常,jquery get 函数也不起作用?

发布于 2024-09-08 21:29:27 字数 758 浏览 1 评论 0原文

我正在使用 jquery 访问 Last.FM API 的方法。这是我的 jquery 代码:

$.get('http://ws.audioscrobbler.com/2.0/','method=user.getweeklytrackchart&user=rj&api_key=fb04ae401284be24afba0fbc2f4b0efb', function(data,status) { 
        console.debug("in result method");
        console.debug(data);
});

这是控制台输出:

替代文本 http://img340。 imageshack.us/img340/3222/screenshot20100713at623.png

所以出于某种原因它不是。奇怪的是,如果我只是粘贴 来自控制台的 URL,工作正常。为什么在网页中使用时不起作用?感谢您的阅读。

I'm using jquery to access a method of the Last.FM API. Here is my jquery code:

$.get('http://ws.audioscrobbler.com/2.0/','method=user.getweeklytrackchart&user=rj&api_key=fb04ae401284be24afba0fbc2f4b0efb', function(data,status) { 
        console.debug("in result method");
        console.debug(data);
});

Here is the console output:

alt text http://img340.imageshack.us/img340/3222/screenshot20100713at623.png

So for some reason it's not. The weird thing is, if I just paste in the URL from the console, it works fine. Why would it not work when used in the webpage? Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

终难愈 2024-09-15 21:29:27

作为安全措施,浏览器不允许跨域 AJAX 调用。有很多方法可以解决这个问题,但您需要访问目标服务器。

最简单的解决方案是使用服务器作为代理来进行调用并将结果返回给 jQuery 脚本。

另请参阅有关 SO 的其他相关问题。

请参阅https://stackoverflow.com/search?q=jquery+ajax+cross+domain

Browsers do not allow cross-domain AJAX calls as a security measure. There are ways around it but you need access to the target server for that.

The simplest solution is to use your server as a proxy to make the call and return the results back to the jQuery script.

Also see other related questions on SO.

See https://stackoverflow.com/search?q=jquery+ajax+cross+domain

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