IONIC, Access-Control-Allow-Origin

I am trying to send an http request using $ http (angular) using this code:

$http({
              method: 'GET',
              url: 'http://192.168.0.17:9000',
              header: {'Access-Control-Allow-Origin': "*"},
        }).then(getEventsSuccess, getEventsError);

But this does not work, and I have this error in the web console:

XMLHttpRequest cannot load http://192.168.0.17:9000/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

Do you have a solution?

+3
source share
1 answer

You see this error due to a security mechanism implemented in your browser called Same Origin Policy.

This is mainly due to the fact that your web page is trying to access a resource that is on a server that is on a different host, port or schema (HTTP / HTTPS / file, etc.) than the web page itself.

To solve this problem, you can do one of the following:

: https://en.wikipedia.org/wiki/Same-origin_policy https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

+4

All Articles