0

I am able to make a cross-origin request after using a chrome extension but I want to make requests without using the extension.

$http.get(URL+"?id="+$scope.source, {headers:{'Access-Control-Allow-Origin': '*'}}).then(function(response) {

    some function.....
})      

when I don't use the extension I get the following error and I have changed the url in error, it was showing the url to which I am making the request

XMLHttpRequest cannot load http://100.100.100.100:100. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
  • You need to enable CORS in server. – John May 11 '17 at 11:02
  • enabling core is a backend issue not frontend ,so in your backend server you should enable them and there are many ways to do that – Fadi Abo Msalam May 11 '17 at 11:02
  • 1
    what i still don't understand is how come the chrome extension is able to dodge the CORS issue :( – snippetkid May 11 '17 at 11:07
  • 1
    @snippetkid — See the section "Why the Same Origin Policy only applies to JavaScript in a web page" on the accepted answer of the duplicate question. – Quentin May 11 '17 at 11:11

1 Answers1

0

As said in the comments, CORS is a backend issue. You have to enable it in your server.
How to do it depends on what language you use.
For exemple with nodejs you should have something like this in your app.js/server.js:

res.header("Access-Control-Allow-Origin", "*");
Karim
  • 126
  • 2
  • 11