1

I created simple simple web site:

        require([
      "esri/map",
      "esri/config",
      "esri/dijit/InfoWindowLite",
      "esri/InfoTemplate",
      "dojo/dom-construct",
      "dojo/domReady!"
    ], function (
        Map,
        esriConfig,
        InfoWindowLite,
        InfoTemplate,
        domConstruct
       ) {
        esriConfig.defaults.io.proxyUrl = "http://111.111.111.111:6969/agsproxy/proxy.ashx"
        esriConfig.defaults.io.alwaysUseProxy = true;
        var customExtentAndSR = new esri.geometry.Extent(-437000, -1244500, -409000, -1239500, new esri.SpatialReference({ wkid: 5514 }));
        map = new Map("mapDiv", { logo: false, extent: customExtentAndSR, nav: false, slider: false, fitExtent: true, fadeOnZoom: true, showAttribution: false });
        var infoWindow = new InfoWindowLite(null, domConstruct.create("div", null, null, map.root));

infoWindow.startup();
 map.setInfoWindow(infoWindow);
 var template = new InfoTemplate();
var featureLayer = new esri.layers.FeatureLayer("http://111.111.111.111:6969/ags/rest/services/VSLP2014/jprl_plochy/MapServer/0", {
 mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
 infoTemplate: template,
 outFields: ["*"]
 });
 map.addLayer(featureLayer);
    });

When I use "MODE_SNAPSHOT" for my featurelayer, layer is displayed and is possible to display infotemplate. But when I run my web site again, It seems to be problem with CORS (No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:12345' is therefore not allowed access.). Once is everything OK, once not. When I run my web site 10 times, approximatelly 5 times is problem with CORS. When I use "MODE_ONDEMAND" it´s OK but when I zoom my layer, problem with CORS is displayed and zoomed layer is not displayed. When I used this sample code with the same layer but as dynamicservicelayer with labels, It seems to be OK. Could someone help me with this problem ? Is it problem with settings in proxy ?

1 Answer 1

2

When communicating to a service using the Esri Javascript API, a proxy page will only avoid CORS issues if the proxy page uses the same URL prefix as the original web site.

So, if your web site is http://localhost:12345/path/to/index.html, the request to: http://111.111.111.111:6969/agsproxy/proxy.ashx?http://111.111.111.111:6969/ags/rest/services/VSLP2014/jprl_plochy/MapServer/0 ...is still crossing an origin and will trigger the CORS preflight and checks.

If you can run the proxy page somewhere behind http://localhost:12345, then you should not see the CORS errors.

I'm not sure why you only see the problem about half the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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