function getAsyncJSONArray()

in source/javascripts/phonebook.js [52:98]


function getAsyncJSONArray(urls, finalCallback) {
   var obj = document.getElementById('progress');
   if (fetchCount == 0) {
      fetchCount = urls.length;
   }

   if (urls.length > 0) {
      var a = urls.shift();
      var URL = a[0];
      var desc = a[1];
      var cb = a[2];
      var xmlHttp = null;
      if (window.XMLHttpRequest) {
         xmlHttp = new XMLHttpRequest();
      } else {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }

      if (obj) {
         obj.innerHTML = "loading file #" + (fetchCount - urls.length) + " / " + fetchCount + "<br>" + desc
      }
      var start = Date.now()
      xmlHttp.open("GET", URL, true);
      xmlHttp.onreadystatechange = function(state) {
         if (xmlHttp.readyState == 4) {
            if (cb) {
               if (xmlHttp.status == 200) {
                  elapsed = Date.now() - start
                  cb(JSON.parse(xmlHttp.responseText));
                  // must be done after as cb creates the hash
                  info[desc]['elapsed'] = elapsed
               } else {
                  cb({});
                  alert("Error: '" + xmlHttp.statusText + "' while loading " + URL)
               }
            }
            getAsyncJSONArray(urls, finalCallback);
         }
      }
      xmlHttp.send(null);
   } else {
      if (obj) {
         obj.innerHTML = "building page content..."
      }
      finalCallback();
   }
}