やあみんな、私のサイトにいくつかのajaxコードを追加しようとしています。私はphpを知っていますが、ajaxは私にとって新しいので、w3schools.comの例を使用して、その一部を変更しました。スクリプトfirebugを使用していると、次のエラーが発生します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>
です。つまり、すべて問題ありません。