You should
only use the responseText property when (xmlhttp.readyState == 4) and (xmlhttp.status == 200). Try that and see if it works.
code:
(...)
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// Data is available now
DoSomethingUseful(xmlhttp.responseText);
}
}
}
xmlhttp.send();
And forget about while loops for doing that. Seriously. Forget it.