Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript callbacks
    primarykey
    data
    text
    <p>I use ajax to get a list of locations then to mark google map based on the array created from the ajax result. How do I make the callback function to have ajax call, array constructed, mark google map all synchronized.(updateMapMarkers() isn't called) Here is my code. Thanks</p> <pre><code>// main function to do work // need timer calling getLocations() function loadMapList() { // initial google map here var count = 40; $("#countdown").html(count + " seconds remaining!"); getLocations(); count--; timeout = setInterval(function(){ $("#countdown").html(count + " seconds remaining!"); if (count == 0) { count =40; getLocations(); } count--; }, 1000); } // using ajax to get location info function getLocations(){ var url = "getLocations"; $.ajax({ type: 'GET', url: url, dataType: 'json', async: false, success: function(data){ if (data.locationList == null || data == 'undefined') { return; } allLocArray.length = 0; for (i in data.locationList) { allLocArray[i] = new Array(3); allLocArray[i][0] = data.locationList[i].LOCATE_NAME; allLocArray[i][1] = data.locationList[i].LATITUDE; allLocArray[i][2] = data.locationList[i].LONGITUDE; } }, error: function(xhr, textStatus, error){ alert(xhr.statusText); alert(textStatus); alert(error); } }); } // mark google map using global var array function updateMapMarkers() { var myOptions = { zoom: zoomLevel, center: new google.maps.LatLng(centerLat, centerLong), mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); for (var i=0; i&lt;allLocArray.length; i++) { var myLatLng = new google.maps.LatLng(allLocArray[i][1], allLocArray[i][2]); var marker = new google.maps.Marker({ position: myLatLng, map: map, title:allLocArray[i][0] }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload