At the beginning of my script, I set a default value for the name of a kmz file that I need for Google Maps. This value is stored in a window variable.
window.kmz="Delaware_River_Basin.kmz"
After running an ajax request, I receive the correct value for the kmz file, which gets stored in the window kmz variable. The script is working fine and returning the expected result.
$.ajax({
type: 'POST',
dataType: 'json',
url: '/includes/kmz.php',
data: {id: window.whichID},
success: function(data) {
window.kmz = data[0];
},
});
Later on in the code, I need to use this kmz file for the maps.
var watersheds = new google.maps.KmlLayer({
url: 'http://' + window.location.hostname + '/map/' + window.kmz + '?a=2',
suppressInfoWindows: true
});
watersheds.setMap(map);
In Mozilla, the window.kmz variable always receives the value from the ajax call. However, in Explorer and Chrome, the default value is retained instead of the value from the ajax call. It seems like there is a delay in updating the variable for Explorer and Chrome. Interestingly, if I add an alert box to display window.kmz before defining the watersheds variable, it shows the default value first and then updates correctly with the ajax value. Why does Mozilla handle this differently compared to Explorer and Chrome?