I'm New to JS - just want to start with that.
Look at this simple example, where i want to draw X number of gauges, where X is taken from the JSON via Ajax call.
<body>
<div id="gServer"></div><BR>
<script type="text/javascript" language="javascript">
/*
 * Obtain number of sessions and Server Status
 * Number of sessions is used to draw gauge per session
 */
$.ajax({
   url: url,
   dataType: 'json',
   data: jd,
   success: function(data)
   {
       //
       Server_CpuCount = data.Server_Cpu_Count;
       Server_LoadAverage = data.Server_Load_Average;
       Server_Sessions = data.Server_Sessions_Count;
       // Create Gauge for every session connected
       for (i = 0; i < Server_Sessions; i++)
       {
        arr.push(new JustGage({
                         id: "g"+i,
                         value: parseFloat(data[i].Session_Load_Average).toFixed(2),
                         min: 0,
                         max: data[i].Session_Cpu_Count,
                         title: data[i].Session_Name,
                         label: "load"
                         }));
       }
       // Create main Server Gauge
       gServer = new JustGage({
                          id: "gServer",
                          // truncate to 2 digits
                          value: parseFloat(Server_LoadAverage).toFixed(2),
                          min: 0,
                          max: Server_CpuCount,
                          title: "GridMan Server",
                          label: "load average"
                          });
   }
   });
// Write out label
document.write(Server_Sessions + "<p>sessions</p><BR>");
// Render All Sessions Gauges
// !! It does not work, ajax is async and Server_Sessions is 0
for (i = 0; i < Server_Sessions; i++)
{
    document.write("<div id=\"g"+i+"\"></div>");
}
</script>
</body>
This part doesn't work, as AJAX is spawned asynchronously therefore Server_Sessions is always 0 !
 for (i = 0; i < Server_Sessions; i++)
    {
        document.write("<div id=\"g"+i+"\"></div>");
    }
How can i draw gauges for sessions if this variable is always 0 ?
 
    