0

In my angularjs app, i made this service :

/* ConnectivityService */
fara.factory('ConnectivityService', ['$resource', function ($resource) {

    return $resource(
        'http://www.google.com/',
        null,
        {
            'check': {method: 'GET', isArray: false, cache: false}
        }
    );
}]);

called like that

    /* ----- SERVICE ConnectivityService.check(); ----- */
    ConnectivityService.check(function(responseSCon) {

        // show response
        console.log(responseSCon);

    }, function (msg) {
        // final reject
    });

but i have this error

XMLHttpRequest cannot load http://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'my-website-here' is therefore not allowed access.

I don't understand, it's not a POST request, it's GET, so why this warning ?

zelocalhost
  • 1,175
  • 3
  • 20
  • 39
  • CORS (https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) are forbidden in browser. You should created your own backend. – Łukasz Jul 02 '15 at 21:22

1 Answers1

1

How to correctly ping any website with angularjs

You can't. XHR is limited by the Same Origin Policy. Unless the other site plays with you (via Cross-Origin Resource Sharing, and provided your user is using a supporting browser), you can't play with it.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875