1

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 );
  }
});

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jack
  • 16,276
  • 55
  • 159
  • 284
  • 1
    You can't do an Ajax request on an external URL http://en.wikipedia.org/wiki/Same_origin_policy – Pekka Aug 29 '11 at 18:35
  • 1
    Cross domain security issue. Check out JSONP http://en.wikipedia.org/wiki/JSONP Another way around this issue is to call a server-side method on your domain to proxy the call to google.com – Kris Krause Aug 29 '11 at 18:39
  • 1
    possible duplicate of [jQuery AJAX with two domains](http://stackoverflow.com/questions/2907737/jquery-ajax-with-two-domains) – Quentin Aug 29 '11 at 18:42

3 Answers3

2

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.

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
0

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.

Sourabh
  • 1,757
  • 6
  • 21
  • 43
0

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?

Community
  • 1
  • 1
Scherbius.com
  • 3,396
  • 4
  • 24
  • 44