Geoserver中跨域问题解决
原创
©著作权归作者所有:来自51CTO博客作者霸道流氓的原创作品,请联系作者获取转载授权,否则将追究法律责任
场景
GeoServer简介、下载、配置启动、发布shapefile全流程(图文实践):
上面安装Geoserver的基础下。
使用ajax请求GeoJson时提示跨域
注:
博客: 霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
1、ajax请求代码示例
var url = "你的url";
//ajax调用
$.ajax({
url:url,
dataType: 'json',
outputFormat:'text/javascript',
success:function(data){
searchPolygon.addData(data);
},
error:function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus+";"+errorThrown);
},
});
2、Geoserver默认是不支持跨域的,来到Geoserver的安装目录下
webapps/geoserver/WEB-INF/web.xml
编辑该文件
3、放开如下两个地方的CORS配置
4、重启geoserver的服务即可。