views:

38

answers:

3
$(function(){
    $.getJSON('http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=ElicitBelief&api_key=25135a535781328243f9e31968abc14&format=json', function(data) {
      alert(data)
    });
});

Firebug says: GET http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=ElicitBelief&api_key=25135a535781328243f9e31968abc14&format=json 200 OK 144ms and the URL is red, so it's presumebly not fetching the data at all.

I can't think what the problem is.

A: 

Visiting that URL gives me a file that says, "Invalid API key - You must be granted a valid key by last.fm"

Tom
Well -- I hope he changed the key when he posted the code.
tvanfosson
+1  A: 

Presumably the url is in a different domain. You'll need to use JSONP and add &jsoncallback=? to your query. I assume that the audioscrobbler API supports this.

tvanfosson
A: 

According to that link http://www.ibm.com/developerworks/library/wa-aj-jsonp1/, you have to add an "&callback=?" at the end of your URL (reason for this, is that jQuery automaticly uses JSONP to bypass AJAX Cross Domain policy when using $.getJSON).

So, if you pass below url to getJSON: http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=ElicitBelief&api_key=25135a535781328243f9e31968abc14&format=json&callback=? you'll get JSON respoonse with : "Invalid API key - You must be granted a valid key by last.fm"

Check this for demo: JSBin (page is empty, but look at requests in Firebug console)

singles