0

So I have a piece of code defines the name of a kmz file I need to drop in Google Maps. I define it at the top of the script as a window var with a default value

 window.kmz="Delaware_River_Basin.kmz"

Now I run some ajax and return what the window kmz should really be. This always is returning the correct answer. Nothing wrong with this script.

$.ajax({
   type:'POST',
   dataType:'json',
       url:'/includes/kmz.php',
       data:{id:window.whichID},
       success:function(data) {
         window.kmz=data[0];
      },   

});

Later on down the page I now need to get this kmz file into maps

 var watersheds = new google.maps.KmlLayer({
     url:'http://' + window.location.hostname + '/map/'+window.kmz+'?a=2',
     suppressInfoWindows: true
 });
  watersheds.setMap(map);

The window.kmz in Mozilla always comes in correctly as the call from the ajax. In Explorer and other browsers the window.kmz is not the ajax call but always the default. The kicker here is if I alert box window.kmz prior to the watershed var being defined it will alert the default but then the actual ajax call works. It is like it needs a pause to find that ajax call! Why does Mozilla work with it but Explorer and Chrome gag? Chrome sometimes gags but Explorer is totally out.

jeynon
  • 322
  • 6
  • 16

1 Answers1

0

Every code requires kmz need to be located in success callback. Or if it is your server you can set cookies on the server side and you will be able to get kmz synchronously

Max
  • 1,824
  • 13
  • 22