XML Http Request Open—Using True

By changing the third parameter in the open call to “true”, you tell the XMLHttpRequest object to continue the execution after the request to the server has been sent.

 Because you cannot simply start using the response from the server request before you are sure the request has been completed, you need to set the onreadystatechange property of the XMLHttpRequest, to a function (or name of a function) to be executed after completion.

In this onreadystatechange function, you must test the readyState property before you can use the result of the server call.

 Simply change the code to

 xmlhttp.onreadystatechange=function()

{

 if(xmlhttp.readyState==4) HB: // request is complete {document.getElementById('test').innerHTML=xmlhttp.

 responseText}

}

xmlhttp.open("GET",url,true);

 xmlhttp.send(null);