Enabling Cross Origin Resource Sharing (CORS) on Google Chrome for JavaScript API calls and Debugging purposes .
I recently started hacking around jQuery and AngularJS. I am a bit late to the party, I admit.
After a few hours of beginning, I had to make Ajax api requests to a domain not residing on my localhost.
That was when I came across a Cross Origin Resource Sharing (CORS) specific problem. Apparently, most browsers stop JavaScript from accessing resources that don't reside on the same server as the js file itself.
After a bit of research, I came across a little hack for Google Chrome that enables CORS.
Just start your chrome with this command :
$google-chrome --disable-web-security
This enables CORS on chrome for that session and enables you make your api calls.
Still hacking around JavaScript and I must say, I am loving it.
** EDIT 1 : **
As @pmcjury pointed out, you could just :
Enable CORS on your server serving the api.
Access-Control-Allow-Origin: *
Visit : http://enable-cors.org/*
Related protips:
jQuery: When to use $(document).ready() and when $(window).load()
Written by Akapo Damilola Francis
Related protips
3 Responses
thanks!
You should enabled CORS on your server serving the api.
Access-Control-Allow-Origin: *
@pmcjury Yeah. But in this particular case, there was no access to the server.