hese
hese

Reputation: 3417

jQuery.get() fails with full url

var url = "/example/somelink";
jQuery.get( url, params, callback);  //works fine

var url = "http://www.yahoo.com";
jQuery.get( url, params, callback);  //fails!

when I give the full URL of a site, get() fails...any idea why this is happening?

Thanks

Upvotes: 4

Views: 809

Answers (2)

user113716
user113716

Reputation: 322542

If by "fails", you mean that you're unable to access the HTML you hoped to receive, this is prevented by the browser for security reasons.

You can manipulate the response only if it comes from the same domain from which the request is sent.

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630569

You can't access a remote domain like this, only your own domain. The difference is the domain, not the full vs relative URL.

It's the same origin policy that's blocking you here, you have to use JSONP to get data directly or proxy the request through your own domain.

Upvotes: 5

Related Questions