我有这个脚本:
[代码]
function getCoords() {
$.ajax({
url: "trainspotter_api.php",
type: "GET",
cache : false,
data: {
action : "trainset",
number : '1234'
},
dataType: "text",
success: function(returnedData) {
var jsondata = jQuery.parseJSON(returnedData);
//console.log(returnedData);
var coords = jsondata.Latitude+','+jsondata.Longitude;
//console.log('Lat: '+jsondata.Latitude);
var coordsArray = coords.split(",");
moveMarkerMap(coordsArray[0], coordsArray[1]);
infoWindow(jsondata.MaterieelDeelNummer,jsondata.GpsDatumTijd,jsondata);
map.setCenter(marker.getPosition());
setTimeout(getCoords, 5000);
},
done: function(data) {
// don't works!
}
});
}
function infoWindow(nummer,GPSdate,snelheid) {
console.log(nummer,GPSdate,snelheid);
// create infowindow!
var infowindow = new google.maps.InfoWindow({
//content: GPSdate
content: 'Trainset: '+nummer+': Velocity:'+snelheid+' km/u<br />Last update!:'+GPSdate
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
function moveMarkerMap(lat,lon) {
console.log('moveMarkerMap geladen!');
var newLatLang = new google.maps.LatLng(lat,lon);
map.panTo(newLatLang);
marker.setPosition(newLatLang);
//infowindow.open(map,marker);
}
[/代码]
如何在每次AJAX请求后刷新infowindow。最新值在 console.log 中是可访问的。但是我如何将它们放在信息窗口中,并在每次请求后刷新它们?