I have an PHP file that automatically search a directory for png files. This file is called update.php. This file contains an array ($files) with this images.
Now I get this array in javascript with json_encode, and this is working fine. Every minute there is a new image in my directory. But when I am using autorefresh with settimeout, then the array not updating.
Script:
function vulArray() {
for (k=0; k<dataArray.length; k++) {
imagesArray[k].setMap(null);
}
// data arrays leeg gooien
dataArray.splice(0,dataArray.length); // data array leeggooien
imagesArray.splice(0,imagesArray.length); // oude array leegmaken
dataArray = <?php echo json_encode($files); ?>; // php array omzetten naar javascript array
var overlayOpts = {opacity:0.0} // Standaard dekking op 0 zetten
// data array vullen met nieuwe data
for (k=0; k<dataArray.length; k++) { // loop starten
var url = dataArray[k]; // images uit de dataarray toewijzen
image = new google.maps.GroundOverlay(url, borders, overlayOpts); // nieuwe laag aanmaken
image.setMap(map); // imagelaag op de map zetten
imagesArray.push(image); // imagelaag in de array pushen
}
refreshImage = setTimeout(function() {
DownloadUrl("update.php", vulArray);
}, 15000); // 5 minuten = 300000
}
The DownloadUrl function:
function DownloadUrl(url, callback) {
var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
request.onreadystatechange = function() {
if(request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
The file is executed every 15 seconds, this is working fine, but nothing will be updates for some sort of reason. Im emptying the arrays in the beginning of the function, but it still outputs the same array.