arcgis api for JavaScript _跨域请求

0
分享 2018-03-27
arcgis api for JavaScript 中出现跨域请求是常见问题,
通常出现类似如下错误消息类似:
XMLHttpRequest cannot load http://10.32.2.70:8399/ArcGIS/rest/info?f=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:58374' is therefore not allowed access.
什么是跨域:http://blog.csdn.net/lambert31 ... 83775
怎样解决:
参考 https://developers.arcgis.com/ ... .html
esriConfig.defaults.io.corsEnabledServers 这一段,把要访问的服务对应的server地址添加进去:
require(["esri/config"], function(esriConfig) {
esriConfig.defaults.io.corsEnabledServers.push("localhost:6080");
});
如上代码所示,localhost:6080 即 server 服务所在arcgis server 地址。
以上为 arcgis api for JavaScript 3.x 所使用的方法,arcgis api for JavaScript 4.x 修改为: 参考:https://developers.arcgis.com/ ... .html 其中的 corsEnabledServers 这一段

Example: // Add a known server to the list. require(["esri/config"], function(esriConfig) { esriConfig.request.corsEnabledServers.push("localhost:6080"); }); 实际代码如下图所示(以 4.x 版本为例):


如果还不行就需要配置代理,参考文档https://developers.arcgis.com/ ... .html

文章来源:http://www.cnblogs.com/mumu122GIS/p/8482445.html

0 个评论

要回复文章请先登录注册