ben
ben

Reputation: 29797

jquery get function not working, even though the URL of the request works fine?

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 http://img340.imageshack.us/img340/3222/screenshot20100713at623.png

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.

Upvotes: 0

Views: 1106

Answers (1)

Anurag
Anurag

Reputation: 141889

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

Upvotes: 3

Related Questions