Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax传递下拉菜单值_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript Ajax传递下拉菜单值

Javascript Ajax传递下拉菜单值,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我正在尝试传递所选下拉菜单项的值,使用下面的代码,我可以使用单个数字,如“1”或“2”,但当我尝试传递文本时,该值设置为“0”。使用Ajax在另一个页面上运行变量时,需要知道变量的值 HTML页面====== <html> <head> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return;

我正在尝试传递所选下拉菜单项的值,使用下面的代码,我可以使用单个数字,如“1”或“2”,但当我尝试传递文本时,该值设置为“0”。使用Ajax在另一个页面上运行变量时,需要知道变量的值

HTML页面======

 <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>  

函数showUser(str)
{
如果(str==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“getuser.php?q=“+str,true”);
xmlhttp.send();
}
选择一个人:
B0012345
COM601
我什么都没有
身份证四号

此处将列出人员信息。
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);
?> 


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

问题是
$q=intval($\u get['q'])中的
intval()
字符串很可能返回0,尽管这取决于字符串最左边的字符。你没有收到任何美元的通知吗?您需要将其更改为$\u GET$_GET是PHP中的一个超级全局变量,用于访问通过查询字符串传递的值。有关更多信息,请访问php.net网站谢谢@Spokey你知道我可以用什么代替intval吗?有点新手。