【问题标题】:TypeError: document.getElementById(...) is null GetAsyncOnlineTypeError: document.getElementById(...) is null GetAsyncOnline
【发布时间】:2014-10-13 01:39:33
【问题描述】:

我得到一个 TypeError: document.getElementById(...) is null 但找不到解决方案...

未捕获的类型错误:无法将属性“innerHTML”设置为 null GotAsyncOnline

在 Firefox 和 chrome 中出现此错误

这是脚本:

<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()">

【问题讨论】:

  • 你有id为“status_online”的元素吗?
  • 请显示您的 HTML 以便用户能够帮助您。不过,为了缓解眼前的问题,您可以创建一个引用该元素的变量。 var statusOnline = document.getElementById("status_online"); if (statusOnline) { statusOnline.innerHTML = req_online.responseText; }

标签: javascript jquery


【解决方案1】:

是的,我忘记了这部分,

这在身体下方:

<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("status_online").innerHTML= req_online.responseText;

【讨论】:

  • 如果你想澄清你的问题,请edit问题。
猜你喜欢
  • 2012-12-02
  • 2021-02-08
  • 1970-01-01
  • 1970-01-01
  • 2013-11-30
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
  • 1970-01-01
相关资源
最近更新 更多