1

I'm trying to use the openlayers vector class. And the error occurred:

Acess control allow origin header is present on the request resource. Origin null is therefore not allowed acess

I've put tileOptions and yet the error persists. My GeoJSON file is in the www root of geoserver.

<!DOCTYPE html>
<html lang='en'>
<head>
 <meta charset='utf-8' />
 <title>My OpenLayers Map</title>
 <script type='text/javascript' src='OpenLayers.js'></script>
 <script type='text/javascript'>


 var map;

 function init() {
    map = new OpenLayers.Map('map_element', {});     
    //Create a Format object
    var vector_format = new OpenLayers.Format.GeoJSON({});

    //Create a Protocol
    var vector_protocol = new OpenLayers.Protocol.HTTP({
        url:'stops.geojson',
        format: vector_format
    });

    //Create Strategy
    var vector_strategies = [new OpenLayers.Strategy.Fixed()];

    //Create a vector layer that contains a Format, Protocol, and Strategy class
    vector_layer = new OpenLayers.Layer.Vector(
        'More Advanced Vector Layer',
        {
            protocol: vector_protocol,
            strategies: vector_strategies
        },

     {"tileOptions": {
         "crossOriginKeyword": null
     }

    });

    map.addLayer(vector_layer);


  if(!map.getCenter()){
    map.zoomToMaxExtent();
 }
 }


 </script>
</head>

<body onload='init();'> <!-- Chama a função js init() --> 

<!--Elemento HTML onde o mapa é exibido -->
 <div id='map_element' style='width: 500px; height: 500px;'>
 </div>

</body>
</html>
  • Is that the exact error (looks like at least some typos)? Can you check if it really starts with No 'Access-Control-Allow-Origin'... – BradHards Apr 8 '14 at 23:12
  • XMLHttpRequest cannot load file ://...... No 'Acess control allow origin' header is present on the request resource. Origin 'null' is therefore not allowed acess – csf Apr 9 '14 at 12:16
  • Please update the question with the exact error message. (e.g. Does it really say Acess or Access?) – BradHards Apr 9 '14 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.