views:

24

answers:

1

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

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.

+3  A: 

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 http://stackoverflow.com/search?q=jquery+ajax+cross+domain

Anurag