Skip to main content

this code works with local kml files, but not when the kml files are on my other server, I got 3 error :

OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml 404 (Not Found) XMLHttpRequest.js:220
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml Origin http://localhost is not allowed by Access-Control-Allow-Origin. XMLHttpRequest.js:220
XMLHttpRequest cannot load http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

so, iI try to put headers in the OpenLayers.Protocol.HTTP. but it still is not working -_-. here is my code:

map = new OpenLayers.Map('map');
osm = new OpenLayers.Layer.OSM();
vectors = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: url_file,//the file is on an other_server(a play server).
        headers: {
            "Access-Control-Allow-Origin":"*",
            "Access-Control-Allow-Headers":"Access-Control-Allow-Origin"},
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true,
            maxDepth: 2
        })
    })
});
map.addLayers([osm, vectors]);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.EditingToolbar(osm));
vectors .events.register("loadend", vectors , function (e) {
    map.zoomToExtent(vectors .getDataExtent());
});

I dont know if i'llI can configure a proxy. So if iI can solve this problem without it'sit it would be great :)

this code works with local kml files, but not when the kml files are on my other server, I got 3 error :

OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml 404 (Not Found) XMLHttpRequest.js:220
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml Origin http://localhost is not allowed by Access-Control-Allow-Origin. XMLHttpRequest.js:220
XMLHttpRequest cannot load http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

so, i try to put headers in the OpenLayers.Protocol.HTTP. but it still not working -_-. here is my code:

map = new OpenLayers.Map('map');
osm = new OpenLayers.Layer.OSM();
vectors = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: url_file,//the file is on an other_server(a play server).
        headers: {
            "Access-Control-Allow-Origin":"*",
            "Access-Control-Allow-Headers":"Access-Control-Allow-Origin"},
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true,
            maxDepth: 2
        })
    })
});
map.addLayers([osm, vectors]);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.EditingToolbar(osm));
vectors .events.register("loadend", vectors , function (e) {
    map.zoomToExtent(vectors .getDataExtent());
});

I dont know if i'll can configure a proxy. So if i can solve this problem without it's great :)

this code works with local kml files, but not when the kml files are on my other server, I got 3 error :

OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml 404 (Not Found) XMLHttpRequest.js:220
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml Origin http://localhost is not allowed by Access-Control-Allow-Origin. XMLHttpRequest.js:220
XMLHttpRequest cannot load http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

so, I try to put headers in the OpenLayers.Protocol.HTTP. but it still is not working -_-. here is my code:

map = new OpenLayers.Map('map');
osm = new OpenLayers.Layer.OSM();
vectors = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: url_file,//the file is on an other_server(a play server).
        headers: {
            "Access-Control-Allow-Origin":"*",
            "Access-Control-Allow-Headers":"Access-Control-Allow-Origin"},
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true,
            maxDepth: 2
        })
    })
});
map.addLayers([osm, vectors]);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.EditingToolbar(osm));
vectors .events.register("loadend", vectors , function (e) {
    map.zoomToExtent(vectors .getDataExtent());
});

I dont know if I can configure a proxy. So if I can solve this problem without it it would be great :)

Source Link
flairon
  • 11
  • 1
  • 2

cross domain problem with :OpenLayers.Protocol.HTTP

this code works with local kml files, but not when the kml files are on my other server, I got 3 error :

OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml 404 (Not Found) XMLHttpRequest.js:220
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml Origin http://localhost is not allowed by Access-Control-Allow-Origin. XMLHttpRequest.js:220
XMLHttpRequest cannot load http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

so, i try to put headers in the OpenLayers.Protocol.HTTP. but it still not working -_-. here is my code:

map = new OpenLayers.Map('map');
osm = new OpenLayers.Layer.OSM();
vectors = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: url_file,//the file is on an other_server(a play server).
        headers: {
            "Access-Control-Allow-Origin":"*",
            "Access-Control-Allow-Headers":"Access-Control-Allow-Origin"},
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true,
            maxDepth: 2
        })
    })
});
map.addLayers([osm, vectors]);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.EditingToolbar(osm));
vectors .events.register("loadend", vectors , function (e) {
    map.zoomToExtent(vectors .getDataExtent());
});

I dont know if i'll can configure a proxy. So if i can solve this problem without it's great :)