2

any help please ? this error shows when i try to get data from server . my Angular App is in my local computer and the database in a server which i connect to it through internet.

error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://XXXXXXXX.com/XXXXx. This can be fixed by moving the resource to the same domain or enabling CORS.

what is the steps to solve this error ??

4 Answers4

2

Like what Hassene said, this is not due to AngularJS. Instead, the browser is blocking your JavaScript application from making a request across domain boundaries.

To fix this, you should enable the Access-Control-Allow-Origin header in your server response. This is much easier than it sounds, and is documented for many different web servers here.

iainjames9
  • 118
  • 2
1

this is not related to Angular JS, your browser (probably chrome) is blocking cross origin requests you should configure your web server to rewrite local paths you are sending to it to your server paths. example nginx conf:

location /local_path {
    proxy_pass        server_path

    }

in your example:

location /homework {
    proxy_pass         http://XXXXXXXXXXXXX.com/XXXXXXX

    }
Hassene Benammou
  • 369
  • 2
  • 4
  • 11
1

This is because in browsers like chrome, when you initiate a request from domain1.com to domain2.com, chrome automatically creates a OPTIONS request to check with the server wether domain1.com is allowed to send HTTP request to domain2.com or not.

According to your backend technology, you have to enable CORS (Cross-Origin Resource Sharing) in your server and configure it to allow domain1.com to access it.

firiz
  • 98
  • 1
  • 1
  • 5
1

If you want a quick fix during development, use a plugin to enable CORS in your browser: plugin for Chrome.

Learn more about CORS here. Then read the accepted answer here.

Community
  • 1
  • 1
Karma
  • 2,196
  • 1
  • 22
  • 30