1

我试过这段代码:

var xmlHttp = new XMLHttpRequest();

function activecomm(comm_id,a_link_id)
{
    var postComm = "id="+encodeURIComponent(comm_id);
    var url = 'comments_mgr_proccesser.php'; 
    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = handleInfo(a_link_id);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", postComm.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(postComm);
}

function handleInfo(a_link_id)
{
    if(xmlHttp.readyState == 1)
    {
        document.getElementById("commactiveresult").innerHTML = 'loading ..';
    }
    else if(xmlHttp.readyState == 4)
    {
        var response = xmlHttp.responseText;
        document.getElementById("commactiveresult").innerHTML = response;
    }
}

当元素readyState == 1的内容commactiveresult被更新,但readyState == 4在同一个元素中没有显示任何内容时。

请问有谁知道是什么问题?

4

1 回答 1

1

您正在调用该handleInfo函数,而不是分配一个就绪状态处理程序。尝试

xmlHttp.onreadystatechange = function (){
    handleInfo(a_link_id);
};
于 2013-03-22T16:45:16.920 回答