开发者

Can't get HTML page from other site with jQuery ($.get, $.ajax) [duplicate]

This question already has an answer here开发者_如何学运维: Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜