简体   繁体   English

HTTP获取JQuery中的请求到Last.fm

[英]HTTP Get Request in JQuery to Last.fm

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. 我正在尝试使用JQuery发出HTTP Get请求,但我得到一个空字符串作为响应,所以我认为我做错了。 I used the documentation from http://api.jquery.com/jQuery.get/ as a guide. 我使用http://api.jquery.com/jQuery.get/中的文档作为指南。

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 但我收到语法错误[打破此错误] \\ n

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

Latest edit: It seems this is because last.fm is responding with html not JSON, any ideas would be appreciated 最新编辑:看来这是因为last.fm用html响应而不是JSON,任何想法都会受到赞赏

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. 除非您的脚本是从www.last.fm ,否则由于浏览器强加的www.last.fm 策略限制,您将无法执行此操作。

You should investigate proxying the request through your server. 您应该通过服务器调查代理请求

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. pkaeding部分正确 - 您无法以您尝试的方式执行此操作,但last.fm确实提供了带有json的RESTful API。

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

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

你需要使用jsonp方法我在这里获取数据跨域是一个例子和某人这样做的线程

last.fm will respond with login page... check the docs ... last.fm将以登录页面回复...检查文档...

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. 如果用户未登录Last.fm,则在被要求授予您的Web应用程序使用其帐户的权限之前,他们将被重定向到登录页面。 On this page they will see the name of your application, along with the application description and logo as supplied in Section 1. 在此页面上,他们将看到您的应用程序的名称,以及第1部分中提供的应用程序描述和徽标。

copied from 复制自

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM