本文介绍了我怎样才能得到一个Ajax请求的响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这code:
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
没有显示在相同的元素。
When readyState == 1
the contents of the commactiveresult
element is updated, but when readyState == 4
nothing is shown in the same element.
有谁知道是什么问题吗?
Does anyone know what the problem is please?
推荐答案
您正在呼叫的 handleInfo
函数,而不是分配就绪状态的处理程序。尝试
You're calling the handleInfo
function instead of assigning a ready state handler. Try
xmlHttp.onreadystatechange = function (){
handleInfo(a_link_id);
};
这篇关于我怎样才能得到一个Ajax请求的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!