javascript - 地理服务器上没有 'Access-Control-Allow-Origin'

标签 javascript tomcat openlayers geoserver

map.on('singleclick', function (evt) {
document.getElementById('info').innerHTML = "Nhìn thấy dòng này thì làm lại đi :) !!!";
var view = map.getView();
var viewResolution = view.getResolution();
var source = hcm.getSource();
var url = source.getFeatureInfoUrl(
evt.coordinate, viewResolution, view.getProjection(),
{ 'INFO_FORMAT': 'application/json', 'FEATURE_COUNT': 50 });
if (url) {
$.ajax({
type: "POST",
url: url,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (n) {
var content = "<table>";
for (var i = 0; i < n.features.length; i++) {
var feature = n.features[i];
var featureAttr = feature.properties;
content += "<tr><td>Tên quận:" + featureAttr["name_2"]
+ "</td><td>Số hiệu quận:" + featureAttr["id_2"]
+"</td></tr>"
}
content += "</table>";
$("#info").html(content);
}
});
}
});

这是我获取功能的代码。

我该如何解决这个问题?我编写这段代码是为了创建一个基于 OpenLayers 库和 GeoServer 的 WebGIS。但是当我尝试获取图层的特征时,我遇到了问题。我解决不了!请帮助我!

this is my problem

最佳答案

有一些插件扩展可用于您的浏览器。

转到设置 -> 插件并搜索访问控制允许来源

安装并激活它刷新您的页面!

关于javascript - 地理服务器上没有 'Access-Control-Allow-Origin',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787336/

相关文章:

openlayers - Openlayers 提名

javascript - 为什么 WMS(网络 map 服务)请求以图 block 形式返回?

javascript - 样式 : color and strokewidth in Openlayers?

javascript - 在 Javascript 中对对象属性执行字符串方法

javascript - HTML 导航栏有时在 IE 中损坏(在 IE8、9 和 10 中测试)

javascript - Angular : factory and controller

javascript - 为什么我一直收到 "Cannot call method ' addEventListener' of null”?

java - 没有 autoddl 的 Sakai 11 SQL 迁移

jsp - 对于 Web 应用程序使用 jsp 或 servlet 哪个更快

file - 在没有数据库的情况下保存与 webapplication 相关的数据