开发者

jQuery.get() fails with full url

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

var url = "http://www开发者_JAVA百科.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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜