title: Callback isn't called as many times as expected
body: <p>Employee webpage makes Ajax calls to the node.js web server in a loop. Code as given. All data values are correct. I expect the callback <code>UpdateTeamArr</code> to be called n times where n is equal to the loop max - <code>document.getElementById("deptSelect").options.length</code>. But its called only once. Thanks for your effort and support.</p>
  
  <h3>Client side code:</h3>
  
  <pre><code>for (var i = 1; i &lt; document.getElementById("deptSelect").options.length; i++) {
      var objJSON = {
          "deptid": document.getElementById("deptSelect").options[i].dataset.id,
          "empid": selectedEmployeeId
      }   
      var strJSON = JSON.stringify(objJSON);
      var xmlhttp = new XMLHttpRequest(); 
  
      xmlhttp.open("post", "../../GetEmployeesTeams", true);
      xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState === XMLHttpRequest.DONE &amp;&amp; xmlhttp.status === 200) {
              UpdateTeamArr(xmlhttp);
          }
      }
      xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
      xmlhttp.send("strJSON=" + strJSON);     
      }
  }
  function UpdateTeamArr(xmlhttp) {
  }
  </code></pre>
  
  <h3>Server code:</h3>
  
  <pre><code>app.post('/GetEmployeesTeams', function(req, res) {
  var connection = mysql.createConnection({
      host     : "127.0.0.1",
      port     : 3306,
      user     : "root",
      password : "root",
      database : "lighting"
  });
  var strJSON = req.param('strJSON');
  var objJSON = JSON.parse(strJSON);
  
  connection.connect();
  connection.query("SELECT db_teamemp.teamid, db_department.id AS deptid FROM lighting.db_teamemp, lighting.db_department, lighting.db_team WHERE db_teamemp.empid='" + 
                      objJSON.empid + "' AND db_department.id='" + objJSON.deptid + "' AND db_teamemp.teamid=db_team.id AND db_team.dept=db_department.id;", 
                      function(err, result, fields) {
      if (err)
          throw err;
      else {
          connection.end();
          res.status(200);
          return res.send(result);
      }
      });
  });
  </code></pre>