0

I am testing a web page and some javascript i wrote to make an api call . However when i execute the code in the console in chrome or from the webpage i get the following error

"No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. "

I have not hosted this anywhere and i am opening the html file which is located on my computer.

Is there any way to get around this so that i can test my code and make a successful api call from the browser when the files are located on my computer?

Dawson Loudon
  • 5,989
  • 2
  • 27
  • 31
vijar
  • 613
  • 3
  • 14
  • 23

1 Answers1

0

Same-origin policy prevents you from accessing any external locations from your client javascript code unless those locations explicitly allow you access.

The error means that the API you are calling does not allow such usage (either because they are against it or because they didn't care to allow it). Please contact the API authors to see if they can enable it (pointing them to http://enable-cors.org) or have alternative way of access for your scenario.

Alternatively, you can disable web security in chrome but note that this is only good for local testing (e. g. in console) and is not a solution for end-users.

Community
  • 1
  • 1
kojo
  • 737
  • 6
  • 14