This is my code for displaying geojson in OpenLayers, where "geourl" is directed to a json file in Amazon S3.
geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url:geourl,
format: new OpenLayers.Format.GeoJSON()})
});
But I received the error like this:
> Failed to load resource: the server responded with a status of 403
> (Forbidden) "geourl" Failed to load resource: No
> 'Access-Control-Allow-Origin' header is present on the requested
> resource. Origin 'http://localhost:8081' is therefore not allowed
> access. "geourl" XMLHttpRequest cannot load "geourl" No
> 'Access-Control-Allow-Origin' header is present on the requested
> resource. Origin 'http://localhost:8081' is therefore not allowed
> access.
Nothing changed when I added
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
to my webapp RequestHandler Class.
GeoJSONOptionsclass. Not sure what that means, though. – blah238 Mar 05 '14 at 20:16Access-Control-Allow-Originheader, you also need to handle the so-called preflight process on your web server. More info here: http://www.html5rocks.com/en/tutorials/cors/ – blah238 Mar 05 '14 at 20:37