我有一个创建 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>
最佳答案
也许是线条
var infowindow = new google.maps.InfoWindow({
content: ''
});
出现错误。浏览器控制台上肯定有一些错误。
Ajax 调用是正确的。
关于jquery.ajax() 使用来自 mysql 的 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25489383/