I'm trying to make an API call to a third party service, with the following JS:
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.something.com/apikeyetcetc", false);
xhr.send();
console.log(xhr.status);
</script>
However, at the xhr.send() line, it triggers this error in the browser's console:
XMLHttpRequest cannot load https://api.something.com/apikeyetcetc. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access.
I'm running a local server using MAMP from www.mamp.info on a fresh install of macOS Sierra.
I created a .htaccess file in the same directory as the HTML file I've created, and added the following line:
Header set Access-Control-Allow-Origin "*"
But it doesn't seem to have helped. I see a lot of varying suggestions about CORS on Apache and other configurations, but I want to make sure I know what's going on here before randomly trying things (especially while I still have a clean dev environment). Any thoughts what might be going on?
Edit: The API I'm trying to use is Dark Sky.