Empty XmlHttp responsetext (only Google Chrome)

这一生的挚爱 提交于 2019-12-20 05:21:29

问题


I have a problem with my chat script in Google Chrome. Sometimes the responsetext is empty until you reload the page, but sometimes it's working well. It opens a xmlhttp connection every second and if the first good the ones after that also good. In Firefox it's always good.

var url = "text.php";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = myfunc;
xmlHttp.send(null);

function myfunc()
{
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
        var msg = xmlHttp.responseText;
        alert(msg);
    }
}

回答1:


try this out

var xmlHttp;
xmlHttp=new XMLHttpRequest();
var url = "text.php";
xmlHttp.onreadystatechange = function()
{
    if (xmlHttp.readyState==4 && xmlHttp.status==200)
    {
        var msg = xmlHttp.responseText;
        alert(msg);
    }
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);


来源:https://stackoverflow.com/questions/18162428/empty-xmlhttp-responsetext-only-google-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!