title: Understand Ajax XMLHttpRequest in details
body: <p>I am new to Ajax, and to make things worse, also a Javascript noob, and I have posted the bellow code of a chat script, to retrieve text from db,  in real time, and the code is working, but I need to understand what certain requests are all about. </p>
  
  <pre><code>&lt;script&gt;
  
  function retrieve(){
  
      var xmlhttp;
  
      if(window.XMLHttpRequest){
          xmlhttp = new XMLHttpRequest(); }
          else if(window.ActiveXObject) {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
          else {
              alert('Please update your browser to start chatting');
      }
  </code></pre>
  
  <p>Simply, I understand the above is (I created it) just a function with global variable declared to be assigned whether XMLHttpRequest/ActiveXObject Object is declared depending if browser is IE6,7 and others if not throw in alert...</p>
  
  <pre><code>xmlhttp.onreadystatechange = function(){
          if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){
              document.getElementById("canvas").innerHTML = xmlhttp.responseText;
          }
      }
  </code></pre>
  
  <p>Similarly, the above I assume takes the  <code>onreadystatechange</code> property of the Ajax API and checks for it's state, <code>readyState</code> &amp; <code>status</code> which, if only they match 4 and 200 means, Ajax is working as wanted</p>
  
  <pre><code>t = setTimeout("retrieve()", 2000);
  </code></pre>
  
  <p>I know the <code>setTimeout()</code> is a bit like <code>setInterval()</code> function, which runs the function inside it, every 2 seconds, to check for new messages.</p>
  
  <pre><code>xmlhttp.open("GET", "getajax.php", true);
      xmlhttp.send();
  </code></pre>
  
  <p>Now, the problem is with the above, I can almost understand that the <code>.open</code> method is supposed to get data from <code>getajax.php</code> even though, I have no idea of what <code>true</code> means in this instance, but as far as the <code>xmlhttp.send();</code> I have absolutely no clue, </p>
  
  <p>So, All I need is for you to explain to me what I have missed during my illaboration, and 
  what the last queries mean, just in brief.</p>
  
  <pre><code>  }
      retrieve();
  
  &lt;/script&gt;
  
  &lt;div id="canvas"&gt;&lt;/div&gt;
  </code></pre>