Access-Control-Allow-Origin error while loading map

2843
3
06-26-2014 09:39 AM
BhavinSanghani
Occasional Contributor II
I get following error while loading the map. I guess it's related to cross-domain. Is there any configuration that I need to set while creating map?

XMLHttpRequest cannot load <server url>. Origin <local m/c name> is not allowed by Access-Control-Allow-Origin.
0 Kudos
3 Replies
ScottGunn
New Contributor III
You could try adding the hostname of your server to the CORS enabled server array:

require(["esri/config"], function(esriConfig) {
   esriConfig.defaults.io.corsEnabledServers.push("yourhostname.com");
});


If your server's at 10.1 it should support this, otherwise you might need a proxy.  Check out this article:
https://developers.arcgis.com/javascript/jshelp/ags_proxy.html
0 Kudos
BhavinSanghani
Occasional Contributor II

Actually, I don't want to add proxy page, it would be bit hassle for my customers. I want to handle somehow for webserver configuration part dynamically or whenever I send request if I can change the header. Wondering if changing header with the request is possible through esr/request. I tried esriConfig.defaults.io.corsEnabledServers as you suggested but still gives an error. May be because of the restriction available at webserver level. Is there anything can be done at ArcGIS Server level to enable CORS? I am using ArcGIS Server 10.0.

0 Kudos
KellyHutchins
Esri Frequent Contributor

This error is usually due to the API's automatic detection of CORS support. The JSAPI attempts to access the rest endpoint of the service. If the service doesn't support CORS the request fails and the error you see is logged to the console.

In cases where CORS support is not available either due to lack of browser support for CORS or if the service you are making cross domain requests to does not support it you may need to setup a proxy for use by your application. Details on installing and configuring the proxy can be found here: Esri/resource-proxy · GitHub

0 Kudos