JQuery 中对 Last.fm 的 HTTP Get 请求

发布于 2024-09-07 20:38:11 字数 859 浏览 2 评论 0原文

我正在尝试使用 JQuery 发出 HTTP Get 请求,但我得到一个空字符串作为响应,所以我认为我做错了什么。我使用了 http://api.jquery.com/jQuery.get/ 中的文档作为指导。

我的代码看起来像这样

$.get("http://www.last.fm/api/auth/?api_key=xxxkeyxxx", function(data){
     window.console.log(data);
  });

编辑:我的代码现在看起来像这样

$.getJSON("http://www.last.fm/api/auth/?api_key=c99ddddddd69ace&format=json&callback=?", 
    function(data){
        window.console.log(data);
    });

但是我得到了 语法错误 [中断此错误] \n

它位于 http://www.last.fm/api/auth/?api_key=c99ddddddd69ace&format=json&callback=

最新编辑:看来这是因为 last.fm 响应的是 html 而不是 JSON,任何想法将不胜感激

I'm trying to make an HTTP Get request using JQuery, but I get an empty string as a response, so I figure I'm doing something wrong. I used the documentation from http://api.jquery.com/jQuery.get/ as a guide.

My code looks like this

$.get("http://www.last.fm/api/auth/?api_key=xxxkeyxxx", function(data){
     window.console.log(data);
  });

Edit: My code now looks like this

$.getJSON("http://www.last.fm/api/auth/?api_key=c99ddddddd69ace&format=json&callback=?", 
    function(data){
        window.console.log(data);
    });

But I'm getting a
syntax error
[Break on this error] \n

And it's located in http://www.last.fm/api/auth/?api_key=c99ddddddd69ace&format=json&callback=?

Latest edit: It seems this is because last.fm is responding with html not JSON, any ideas would be appreciated

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

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

发布评论

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

评论(4

树深时见影 2024-09-14 20:38:11

除非您的脚本是从 www.last.fm 提供的,否则您将无法执行此操作,因为 同源策略 浏览器施加的限制。

您应该调查代理请求 通过您的服务器。

Unless your script is being served from www.last.fm, then you will not be able to do this, due to the Same Origin Policy restrictions imposed by browsers.

You should investigate proxying the request through your server.

凡尘雨 2024-09-14 20:38:11

last.fm 将响应登录页面...检查文档...

如果用户没有登录
Last.fm,他们将被重定向到
在被要求之前登录页面
授予您的网络应用程序权限
使用他们的帐户。在此页面上
他们会看到你的名字
应用程序,以及
应用程序描述和徽标为
第 1 节中提供。

复制自

http://www.last.fm/api/webauth

last.fm will respond with login page... check the docs ...

If the user is not logged in to
Last.fm, they will be redirected to
the login page before being asked to
grant your web application permission
to use their account. On this page
they will see the name of your
application, along with the
application description and logo as
supplied in Section 1.

copied from

http://www.last.fm/api/webauth

无人问我粥可暖 2024-09-14 20:38:11

pkaeding 部分正确 - 您将无法按照您尝试的方式执行此操作,但 last.fm 确实提供了带有 json 的 RESTful API。

Last.fm API - http://www.last.fm/api/rest

jQuery API - http://api.jquery.com

pkaeding is partially correct - you wont be able to do this in the way you are attempting, but last.fm does offer a RESTful API with json.

Last.fm API - http://www.last.fm/api/rest

jQuery API - http://api.jquery.com

冷了相思 2024-09-14 20:38:11

您需要使用 jsonp 方法来跨域获取数据这里是一个示例和线程 有人这样做

you need to use jsonp method iin getting data cross domain here is an example and thread of someone doing so

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