title: Synchronous request with ajax in a loop
body: <p>I have a for loop which contains ajax request. The request is working aynchronously. So i can't reach the result of request in time. How can i solve this problem without using any library? 
  Thanks.</p>
  
  <pre><code>    var availables = document.getElementsByClassName("available");
  
      for(var i=0;i&lt;availables.length;i++){
          var element = availables[i];
  
          var xmlhttp;
          if(window.XMLHttpRequest)
              xmlhttp = new XMLHttpRequest;
          else
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  
          xmlhttp.open("GET", "control.php?user=" + element.innerText, true);
          xmlhttp.send();
  
          xmlhttp.onreadystatechange = function(){
              if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){
                  var result = xmlhttp.responseText;
                  console.log(result);
  
                  element.setAttribute("class" , "result available " + result);
                  if(result == "online")
                      element.innerHTML = "&lt;a href=\"http://twitter.com/" + element.innerText + "\"&gt;" + element.innerText + "&lt;/a&gt;";   
              }
          }
      }
  </code></pre>