我得到一个TypeError:document.getElementById(...)为null但无法找到解决方案......
未捕获的TypeError:无法设置null的属性“innerHTML” GotAsyncOnline
firefox和chrome中的这个错误occor
这是剧本:
<script language=javascript type="text/javascript">
<!-- Hide script from non-JavaScript browsers
var req_online;
// GetAsyncOnline sends a request to read the status.
function GetAsyncOnline() {
url = "../../../../../../ivr/consulenten-overzicht.php";
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req_online = new XMLHttpRequest();
req_online.abort();
req_online.onreadystatechange = GotAsyncOnline;
req_online.open("POST", url, true);
req_online.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
req_online.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req_online = new ActiveXObject("Microsoft.XMLHTTP");
if (req_online) {
req_online.abort();
req_online.onreadystatechange = GotAsyncOnline;
req_online.open("POST", url, true);
req_online.send();
}
}
}
// GotAsyncStatus is the read callback for the above XMLHttpRequest() call.
// This routine is not executed until data arrives from the request.
// We update the "fifo_data" area on the page when data does arrive.
function GotAsyncOnline() {
// only if req_online shows "loaded"
if (req_online.readyState != 4 || req_online.status != 200) {
return;
}
document.getElementById("status_online").innerHTML=
req_online.responseText;
// Schedule next call to wait for fifo data
setTimeout("GetAsyncOnline()", 40000);
return;
}
-->
<body onLoad="GetAsyncOnline()">
答案 0 :(得分:0)
是的,我忘记了这一部分,
这低于身体:
<table width="100%" border="0" cellspacing="2" cellpadding="4">
<tr>
<td valign="top">
<div id="status_online">
<center>
<img src="images/loading.gif"><br>
<b><font color="#8791e2" size="2" face="Arial, Helvetica, sans-serif">Laden van Consulenten</font></b>
</center>
</div></td>
</tr>
</tr>
</table>
错误之后,它必须在这一行:document.getElementById(&#34; status_online&#34;)。innerHTML = req_online.responseText;