I have recently updated from OpenLayers 3.0 to 3.7 and I noticed in the 3.5 update the Vector API has changed, I tried to alter the code as per the bottom section of code but i am getting the error below:

XMLHttpRequest cannot load http://PCNAME:8080/geoserver/example/ows?service=WFS&version=1.0.0&re…-180803.92191974312,7068079.039279004,-170676.01567195728,7073596.83725834. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

Code as per below:

var vectorFeatures = function(response) {
    var features = vectorSource.readFeatures(response);

  var geoJSONFormat = new ol.format.GeoJSON();

    var vectorSource = new ol.source.Vector({
      loader: function(extent, resolution, projection) {
        var url = 'http://PCNAME:8080/geoserver/Example/ows?service=WFS&' +
        'version=1.0.0&request=GetFeature&typeName=Example:layer_1&' +
        'outputFormat=text/javascript&format_options=callback:vectorFeatures' +
        '&srsname=EPSG:3857&bbox=' + extent.join(',');
          url: url,
          success: function(data) {
            var features = geoJSONFormat.readFeatures(data);
      strategy: ol.loadingstrategy.bbox

You're running into the same origin policy (https://en.wikipedia.org/wiki/Same-origin_policy)

  • what would be the easiest solution? I also didn't have this issue with older versions of OpenLayers so what's changed? – Joshua Dickerson Jul 30 '15 at 13:25
  • use a relative url or a proxypass on the webserver – bartvde Jul 31 '15 at 9:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.