Can't get HTML page from other site with jQuery ($.get, $.ajax) [duplicate]
Possible Duplicate:
load content from external page into another page using ajax/query
May be I just don't get something.
I want to get html page from other site, let it be http://www.server.com/somepage/param
In my js code:
var url = "http://www.server.com/somepage/param";
$.get(url, callback);
Chrome says "Failed to load resource".
What is wrong?
You're running into restrictions imposed by the Same Origin Policy. In short, AJAX calls to a different domain are prohibited and will always fail.
You need to either use JSONP (mostly applicable to data returned by APIs) or proxy the request through your own server/domain.
The simple answer is, no, this is not possible. Cross Domain AJAX is not allowed. However, you can find a (working) workaround here:
http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html
More details about cross-domain ajax requests: Dashboard Cross-domain AJAX with jquery
精彩评论