Javascript 如何从Ajax请求中获得响应?
我尝试了以下代码:Javascript 如何从Ajax请求中获得响应?,javascript,ajax,xmlhttprequest,Javascript,Ajax,Xmlhttprequest,我尝试了以下代码: 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.onreadystatec
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
时,同一元素中不显示任何内容
有人知道问题出在哪里吗?您正在调用
handleInfo
函数,而不是分配就绪状态处理程序。试一试
xmlHttp.onreadystatechange = function (){
handleInfo(a_link_id);
};
您正在调用
handleInfo
函数,而不是分配就绪状态处理程序。试一试
xmlHttp.onreadystatechange = function (){
handleInfo(a_link_id);
};
在“comments\u mgr\u processer.php”中是:应该编辑到问题中。在“comments\u mgr\u processer.php”中是:应该编辑到问题中。@user2192164如果有效,不要忘记将其标记为您的答案。@user2192164如果有效,不要忘记将其标记为您的答案。