开发者

Jquery not working for external domains

I have a function in Jquery, that try get html from an page:

$.ajax({
  type:'GET',
  url: 'http://www.google.com',
  success: function( data ) {
        alert( data 开发者_StackOverflow社区);
  }
});

why does not works? in firebug I see the communication headers.


you are violating SOP. To avoid SOP uou would likely need a server side script (on your host) to load the external url and return the data to your client side script, or use a service that provides a JSONP results.


Well, for security reasons, Javascript don't allow a page to load a page from external domains. These security reasons are to prevent users from form hijacking, xss attacks etc. If you still want to load external pages, you can use iframes, else you will need an openId kind of thing in your backend.


Cross domain $.ajax is not permitted due to security violation. The only cross domain call that you can do in jQuery is JSONP request.

Please read my answer to this question: JavaScript: How do I create JSONP?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜