Ajax通过下拉菜单值

时间:2013-12-09 14:08:12

标签: javascript php jquery html ajax

我试图通过所选下拉菜单项的值,使用下面的代码,我可以使用单个数字,如“1”或“2”,但当我尝试使用文本时,值设置为'0'。任何想法都是使用Ajax在另一个页面上运行变量所需的值。

HTML PAGE ======

 <html>
<head>
<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;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="B0012345">B0012345</option>
<option value="COM601">COM601</option>
<option value="3">ID Nothing</option>
<option value="4">ID Four</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>  

PHP页面=======

<?php include "db.php" ?>

<?php
$q = intval($_get['q']);

echo $q;



$result = mysqli_query($db_connection, "SELECT * FROM feedback WHERE ModuleCode = '".$q."'");



echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['StudentID'] . "</td>";
  echo "<td>" . $row['FeedbackID'] . "</td>";
  echo "<td>" . $row['ModuleCode'] . "</td>";
  echo "<td>" . $row['Viewed'] . "</td>";
  echo "<td>" . $row['StudentComment'] . "</td>";
  echo "</tr>";
  }
echo "</table>";


echo "Result kk" . $row;

mysqli_close($con);
?> 

1 个答案:

答案 0 :(得分:0)

你是否收到$ _get varibale的通知?如果没有,那么您必须启用错误报告。由于$ _get ['q']未定义,因此您需要将其更改为$_GET['q']。 $ _GET是PHP中的一个超级全局变量,用于访问通过查询字符串传递的值。有关更多信息,请访问php.net网站

相关问题