Json文件未显示在Google Chrome中 [英] Json file dosen't show up in google chrome
问题描述
我正在开发一个页面,该页面通过jQuery和Leaflet显示一个Json文件.
I'm developing a page that shows a Json file via jQuery and Leaflet.
Flickr方面运行良好,但是当我尝试$ .getJSON o时,我在Chrome的控制台中看到一个错误:
The Flickr side is working fine, but when I try to $.getJSON o, I see an error in Chrome's console:
XMLHttpRequest无法加载文件:///C:/AppServ/www/PFEleaflet/test%20geojson/lot.json.跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource.
XMLHttpRequest cannot load file:///C:/AppServ/www/PFEleaflet/test%20geojson/lot.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
但是当我尝试在FireFox中打开.html页面时,将显示Json文件,它工作正常.
But when i try to open the .html page in FireFox, the Json file shows up, it work fine.
这是我正在使用的代码:
This is the code I am using:
var geoLayer = L.geoJson().addTo(map);
var geoList = L.control.geoJsonList(geoLayer);
geoList.on('item-active', function(e) {
$('#selection').text(JSON.stringify(e.layer.feature.properties));
})
.addTo(map);
$('#geofile').on('change', function(e) {
$.getJSON(this.value, function(json) {
map.removeLayer(geoLayer);
geoLayer = L.geoJson(json).addTo(map);
map.fitBounds( geoLayer.getBounds() );
geoList.reload( geoLayer );
});
}).trigger('change');
请帮忙.
推荐答案
建议在本地服务器上打开此页面,而不要使用文件协议,这会在此处和其他地方引起问题. Nodejs的服务很棒,或者是Ruby的内置http服务器.
Suggest opening this page on a local server instead of using file protocol which will cause problems here and other places. Nodejs serve is great, or Ruby's builtin http server.
这是一个很棒的清单. https://gist.github.com/willurd/5720255
Here is a great list. https://gist.github.com/willurd/5720255
这篇关于Json文件未显示在Google Chrome中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!