I had come across this CORS issue but was able to overcome it using jsonp and callback=? like suggested below: XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin I also have '--allow-file-access-from-files' turned on for Chrome and I have hosted this on Google app engine and also loaded it via Firefox.
However, I started using classes in javascript (via CoffeeScript) and it gives me this error when I use the class method. Please note that I am able to overcome this issue by not using the class/instance method below:
Issue: I am trying to show a few locations on a google map. I call the google fusion table api to get my data and display it. It works fine when I call the dataHandler() method like a regular method and not as as class method. When I call it like a class method, I get this error locally: "Origin file:// is not allowed by Access-Control-Allow-Origin." I am trying locally on Chrome. When I deploy/host it on the google app engine, I get this error on the same line '400 (Bad Request) '
Thanks
var myMap = new MyMap();
google.load('visualization', '1.0', {"callback":myMap.initialize});
class MyMap
initialize: -> //Javascript equivalent: MyMap.prototype.initialize = function() {
...
jqxhr = $.get(encodeURI(url), @dataHandler, "jsonp") // Does not work.
//Javascript equivalent: jqxhr = $.get(encodeURI(url), this.dataHandler, "jsonp");
jqxhr = $.get(encodeURI(url), dataHandler, "jsonp") // This works without the @
//Javascript equivalent: jqxhr = $.get(encodeURI(url), dataHandler, "jsonp");
dataHandler: (d) -> // Does not work. Javascript equivalent: MyMap.prototype.dataHandler = function(d) {
dataHandler= (d) -> // This works. Javascript equivalent: dataHandler = function(d) {
Local Error:
XMLHttpRequest cannot load https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyDjfc6i-&sql=SELECT%20Lat,%20Lng%20from%201Stisvr...&callback=?. Origin file:// is not allowed by Access-Control-Allow-Origin.
Hosted/Server Error:
GET https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyDjfc6i-&sql=SELECT%20Lat,%20Lng%20from%201Stisvr...&callback=? 400 (Bad Request)