0

Possible Duplicate:
jQuery.ajax fails when url is from different server

I have a code like this on my test page:

$(document).ready(function() {

    $.get(
        "http://www.google.com",
        function(data) { alert(data); }
    );

});

The problem is, that I never get the alert and I don't know why.

Does anybody know what the error could be? Its a simple html page and all other jQuery stuff is working.

Community
  • 1
  • 1
gurehbgui
  • 14,236
  • 32
  • 106
  • 178

3 Answers3

3

This isn't working for you, because you're trying to perform crossdomain XmlHttpRequest. You might want to check out this Cross domain mod for jQuery

3

The $.get function in jQuery executes an AJAX request with the HTTP type of GET. Due to Same origin policy, you can't request pages from outside of your domain.

If you need to request pages from another domain, you would need to setup a script hosted on your site to proxy these requests.

fin1te
  • 4,289
  • 1
  • 19
  • 16
2

If its google.com you are trying to get then it wont work, XHR only works on your own domain. the other site need to have Cross-site XMLHttpRequest enabled.

voigtan
  • 8,953
  • 2
  • 29
  • 30