来自本地网址的jquery getJSON

时间:2013-04-19 02:50:34

标签: javascript jquery openlayers

大家好我使用openlayer开发网页地图。

我使用geojson,我有以下代码: https://scraperwiki.com/views/openlayers_geojson_example/edit/

这是代码:

<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=?",

当我从iis localhost打电话时它起作用 我试着改变这样:

$.getJSON("assets/json/66016.geojson",
        "callback=?",

但它没有用,:(

请帮助我为什么以及如何使这项工作。

这是错误的:

HTTP错误404.0 - 未找到 localhost ---&gt; /assets/json/66016.geojson?callback = jQuery152048599341535009444_1366340277133&amp; _ = 1366340277237

2 个答案:

答案 0 :(得分:1)

试试这个

$.getJSON("/assets/json/66016.geojson",
        "callback=?",

答案 1 :(得分:0)

对不起伙计们,最后我得到了答案,这就是解决方案:

$.getJSON("assets/json/66016.geojson",
        "callback=?",

只需删除“callback =?”,

$.getJSON("/assets/json/66016.geojson",