 <p>You are overwritting the first value in your variable "myAjax" by assigning it a second value. It would be just like doing something like </p> <pre><code>var x=5; x=7; alert(x); </code></pre> <p>Here x would hold the value of 7, because that was the last value assigned to it.</p> <p>This function </p> <pre><code>myAjax.onreadystatechange=function() { if (myAjax.readyState==4 &amp;&amp; myAjax.status==200) { document.getElementById(div).innerHTML=myAjax.responseText; } } </code></pre> <p>will be called when the server you are calling returns a response. When the first call returns myAjax will be holding the value of the second call already, making the first call not display anything. You need to either assign these two variables synchronously (one after the other one has completed), or assign them to different variable names. </p>