Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

like image 656
Crothers Avatar asked Jul 02 '10 20:07

Crothers


3 Answers

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.

like image 146
pkaeding Avatar answered Oct 05 '22 14:10

pkaeding


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

like image 24
rbawaskar Avatar answered Oct 05 '22 14:10

rbawaskar


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

like image 35
HurnsMobile Avatar answered Oct 05 '22 13:10

HurnsMobile