Php ajax错误xmlhttp.onreadystatechange
我有一个错误:UncaughtTypeError:无法设置null测试的属性“value”:29 xmlhttp.onreadystatechange。当使用ajax时 我的php代码如下所示: 我的代码怎么了Php ajax错误xmlhttp.onreadystatechange,php,Php,我有一个错误:UncaughtTypeError:无法设置null测试的属性“value”:29 xmlhttp.onreadystatechange。当使用ajax时 我的php代码如下所示: 我的代码怎么了 <select name="data" onchange="showUser(this.value)" class="form-combobox"> <?php $qrySelect =
<select name="data" onchange="showUser(this.value)" class="form-combobox">
<?php
$qrySelect = mysql_query("select * from m_motor");
echo'<option>-Choice Data-</option>';
while ($data = mysql_fetch_array($qrySelect)){
echo "<option value=$data[code_motor]>$data[code_motor]</option>";
}
?>
</select>
<div id="txtHint"><b>-Choice Data-</b></div>
在javascript代码中,如下所示:
我的代码怎么了?
请帮帮我
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").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)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
document.getElementById("data").value =xmlhttp.data;
}
}
xmlhttp.open("GET","getAjax.php?q="+str,true);
xmlhttp.send();
}
</script>
您应该将其替换为第一个代码段
此外,我认为不存在xmlhttp.data属性。如果您需要使用ajax传递多个值,请尝试json编码。这是因为您的select标记应该具有id=data而不是name=data,因为您写入的是not working sir:。。。您可以发送指向此解决方案的链接吗?谢谢
<select id="data" onchange="showUser(this.value)" class="form-combobox">
<?php
$qrySelect = mysql_query("select * from m_motor");
echo'<option>-Choice Data-</option>';
while ($data = mysql_fetch_array($qrySelect)){
echo "<option value=$data[code_motor]>$data[code_motor]</option>";
}
?>
</select>
<div id="txtHint"><b>-Choice Data-</b></div>