-1

I am implementing a CORS function to get a JSON object from a cross domain.

But I still see this error: "No 'Access-Control-Allow-Origin' header is present on the requested resource."

Do I need to do something in the server?

Hillel Garcia
  • 109
  • 12
  • That's a CORS error showing that the server your are trying to gather data from does not have any protocol for sending data to a site outside of its domain. Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS. You would need to handle the request on the server. – bj7 Feb 28 '17 at 10:44
  • you need to enable it in server side also – Edison Augusthy Feb 28 '17 at 10:52
  • The section of the tutorial you linked to is called "Adding CORS support to the **server**" … so of course you need to do something in the server! – Quentin Feb 28 '17 at 10:52

1 Answers1

0

Yes you need to make the server send the right headers. With these headers the browser will be able to tell that the request is valid. You need at least this header:

Access-Control-Allow-Origin: http://yourserver.com

And maybe this one if you need to handle cookies:

Access-Control-Allow-Credentials: true
laurent
  • 88,262
  • 77
  • 290
  • 428
  • Nice, thank you. Where should I place this code? in the .htaccess file? – Hillel Garcia Feb 28 '17 at 11:17
  • @HillelGarcia, it depends on your server. With PHP you would simply add this to your PHP file: `header("Access-Control-Allow-Origin: yoursite.com");` – laurent Feb 28 '17 at 12:01