当 Asnyc 设置为 true 时,XMLHttpRequest 不起作用

XMLHttpRequest not works when Asnyc is set to true

在我的网页中:http://ravi4pk.in/chat

您可以在我的第一个 XMLHttpRequest 中看到我已将 Asnyc 参数设置为 0,即 false。

当我将其设置为 true 时,它​​不起作用,怎么了?

如果您使用异步,则需要像这样使用 onreadystatechange 事件:

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        txt = xmlhttp.responseText;
        document.getElementById("a").innerHTML = txt;
    }
};