我有一个页面可以创建json数据并对其进行编码。如果我转到页面,输出看起来像这样:
{"hail":
[
{"date":"140714","time":"1646","size":"100","city":"3 ESE HOUSTONIA","county":"PETTIS","state":"MO","lat":"38.88","lon":"-93.31","other":"(EAX)"},
{"date":"140714","time":"1649","size":"100","city":"HUGHESVILLE","county":"PETTIS","state":"MO","lat":"38.84","lon":"-93.3","other":"US POSTAL WORKER WITH A QUARTER SIZED HAIL REPORT. (EAX)"},
{"date":"140714","time":"1742","size":"175","city":"7 NNE COOLIDGE","county":"HAMILTON","state":"KS","lat":"38.14","lon":"-101.96","other":"(DDC)"}
]
我正在尝试使用
function addMarker(){
alert("success 1");
var infowindow = new google.maps.InfoWindow({
content: ''
});
jQuery.ajax({
url : '/data/hail',
dataType : 'json',
success : function(response) {
alert("SUCCESS");
hail = response.hail;
// loop through places and add markers
for (h in hail) {
//create gmap latlng obj
tmpLatLng = new google.maps.LatLng( hail[h].lat, hail[h].lon);
// make and place map maker.
var marker = new google.maps.Marker({
map: map,
position: tmpLatLng,
title : hail[h].city
});
// not currently used but good to keep track of markers
markers.push(marker);
}
}
})
setAllMap(map);
}
第一个警报响起,但第二个警报从未被调用。我在主索引页面上有jquery的包含
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
答案 0 :(得分:0)
也许是行
var infowindow = new google.maps.InfoWindow({
content: ''
});
发出错误。浏览器控制台上必定存在一些错误。
但Ajax调用是正确的。