0
$.ajax({
            crossDomain: true,
            type: "GET",
            url:"http://simplewebsite.com",
            success: function(data) {
               alert(data);
            }
        }); 

I simply access a site, but success returns empty data. where as it works fine using curl. Any ideas?

Inaccessible
  • 1,560
  • 3
  • 18
  • 42

3 Answers3

4

Google restricts accessing their page using AJAX from a different domain. curl does not make an AJAX request, so it works.

Yauheni Leichanok
  • 1,759
  • 1
  • 21
  • 30
4

Welcome to the world of cross-domain ajax calls.

You can't just do an Ajax call to any website and expect it to work. The server needs to be setup properly for that.

Use ajax calls to contact webservices which allow cross-domain calls, OR to contact your own server. Any other request will likely fail.

Nzall
  • 3,439
  • 5
  • 29
  • 59
2
Sounds like you have a crossdomain problem because there is no 'Access-Control-Allow-Origin' header in the response. 

If this is not the case a browser usually does not allow to request a service located on another domain than the javascript that is triggering the request.

Google does not allow cross domain in

Please check here for for further details

XMLHttpRequest cannot load, No 'Access-Control-Allow-Origin' header is present on the requested resource

And check console here

http://jsbin.com/jajimira/1

Community
  • 1
  • 1
Just code
  • 13,553
  • 10
  • 51
  • 93