[英]jquery getJSON from local url
Hi everyone i develop web map using openlayer. 大家好,我使用openlayer开发网络地图。
i use geojson, i have this code from : https://scraperwiki.com/views/openlayers_geojson_example/edit/ 我使用geojson,我的代码来自: https ://scraperwiki.com/views/openlayers_geojson_example/edit/
this is code : 这是代码:
<script type="text/javascript">
// Start position for the map (hardcoded here for simplicity)
var lat=50.90685
var lon=-1.4029
var zoom=12
var map; //complex object of type OpenLayers.Map
//Initialise the 'map' object
$(function() {
$.getJSON("http://mapit.mysociety.org/area/66016.geojson",
"callback=?",
function(data, textStatus, jqXHR) {
map = new OpenLayers.Map('map', {
layers: [
new OpenLayers.Layer.OSM.Mapnik("Mapnik"),
],
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
maxResolution: 'auto',
});
var lonLat = new OpenLayers.LonLat(lon, lat)
.transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
map.setCenter(lonLat, zoom);
var vector_layer = new OpenLayers.Layer.Vector("GeoJSON");
var geojson_format = new OpenLayers.Format.GeoJSON();
var geometry = geojson_format.parseGeometry(data);
geometry.transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
var feature = new OpenLayers.Feature.Vector(geometry);
vector_layer.addFeatures([feature]);
map.addLayer(vector_layer);
})
});
</script>
in : 在:
$.getJSON("http://mapit.mysociety.org/area/66016.geojson",
"callback=?",
it works when i call from iis localhost i try to change like this : 当我从iis localhost拨打电话时,它会像这样更改:
$.getJSON("assets/json/66016.geojson",
"callback=?",
but it didnt work, :( 但它没有用,:(
please help me why and how to make this work. 请帮助我为什么以及如何进行这项工作。
this is the wrong : 这是错误的:
HTTP Error 404.0 - Not Found localhost --- >/assets/json/66016.geojson?callback=jQuery152048599341535009444_1366340277133&_=1366340277237 HTTP错误404.0-找不到本地主机---> /assets/json/66016.geojson?callback=jQuery152048599341535009444_1366340277133&_ = 1366340277237
Try this 尝试这个
$.getJSON("/assets/json/66016.geojson",
"callback=?",
Sorry guys, finnaly i get my answer this is the solve : 抱歉,好,我得到我的答案,这是解决方案:
$.getJSON("assets/json/66016.geojson",
"callback=?",
just erase "callback=?", 只需删除“ callback =?”,
$.getJSON("/assets/json/66016.geojson",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.