嘿家伙即时试图添加到我的网站一些 ajax 代码。我知道 php,但 ajax 对我来说是新的,所以我在 w3schools.com 上使用了一个示例并更改了其中的一部分。当我使用我的脚本时,萤火虫给了我这个错误:TypeError: document.getElementById(...) is null
。所以我做错了什么我不知道你能帮我吗?这是我的代码:
function showOptionen(str)
{
if (str=="")
{
document.getElementById("Optionen").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//Here in this line is the error:
document.getElementById("Optionen").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","bezeichnungs-optionen.php?q="+str,true);
xmlhttp.send();
}
我检查了我bezeichnungs-optionen.php
的,结果是:<option value="DELL Notebook">DELL Notebook</option>
所以一切正常。