这是我的代码片段,无法理解这有什么问题,因为 xmlhttp.readyState 没有更改为 4。
document.getElementById("opencloseimg").src = "images/minus.jpg";
//The page we are loading.
var serverPage = "calendar.php";
//Set the open close tracker variable.
showCalendar = false;
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage,true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
最佳答案
可能是因为您正在获取的 URL 不可用?
您是否在 JavaScript 控制台中看到任何错误?
在 statechange 函数的开头显示一条消息:
xmlhttp.onreadystatechange = function() {
console.log ('xmlhttp : ' + xmlhttp.readyState + ', ' + xmlhttp.status);
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
查看显示的内容。
关于php - AJAX readyState 在我的代码中没有更改为 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13324870/