Javascript 当我得到$q时变量是未定义的?
我现在使用下面的代码,我想根据rfq显示rfq列表。但当我选择时,$q是未定义的 Dropdown.phpJavascript 当我得到$q时变量是未定义的?,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我现在使用下面的代码,我想根据rfq显示rfq列表。但当我选择时,$q是未定义的 Dropdown.php <?php $con = mysql_connect("localhost","root",""); $db = mysql_select_db("app",$con); $get=mysql_query("SELECT rfq FROM procurement GROUP BY rfq ORDER BY rfq"); $option = '';
<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("app",$con);
$get=mysql_query("SELECT rfq FROM procurement GROUP BY rfq ORDER BY rfq");
$option = '';
while($rows = mysql_fetch_assoc($get))
{
$option .= '<option value = "'.$rows['rfq'].'">'.$rows['rfq'].'</option>';
}
?>
<form>
<select name="users" onchange="showUser()">
<option value="ALL">ALL</option>
<?php echo $option; ?>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
getuser.php
<?php
include('connect.php');
$q=$_GET["q"];
$sql="SELECT rfq FROM procurement WHERE rfq='".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>MOD</th>
<th>RFQ #</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['mode_of_procurement']."</td>";
echo "<td>".$row['rfq']."</td>";
echo "</tr>";
}
echo "</table>";
echo $q;
mysql_close();
?>
全部的
此处将列出人员信息。
getuser.php
但是$q的值没有显示,当我回显$q时,该值是未定义的。为什么呢
这是剧本
<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>
函数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();
}
将
此.value
传递到函数调用中
<select name="users" onchange="showUser(this.value)">
<option value="ALL">ALL</option>
<?php echo $option; ?>
</select>
全部的
最新更新:
我想你想要这个链接
<html>
<script type="text/javascript">
function show() {
var e = document.getElementById('myOption');
var str = e.options[e.selectedIndex].text;
alert(str);
if(str=='All')
{
var x = document.getElementById("myOption");
var txt = "";
var i;
for (i = 1; i < x.length; i++) {
txt = txt + "," + x.options[i].text;
}
}
else{
txt=str;
}
alert(txt);
}
</script>
<body onload="show();">
<form name="myForm">
<select name="myOption" id="myOption" onChange="show()">
<option value="All" >All</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</form>
</body>
</html>
函数show(){
var e=document.getElementById('myOption');
var str=e.options[e.selectedIndex].text;
警报(str);
如果(str=='All')
{
var x=document.getElementById(“myOption”);
var txt=“”;
var i;
对于(i=1;i
Fiddle您是否从url中传递了$\u GET['q']呢?您是否按照代码的预期在url中传递了
q
?jQuery/JavaScript代码在哪里?我在您的脚本中得到的代码很容易受到SQL注入的影响。还有一件事,我如何在选择all时选择所有记录?我希望它在页面运行时自动加载。就像图中那样,我添加了代码,以便在页面加载时能够加载表,但记录没有显示,只有显示的字段才显示。我想在所有的记录中都显示出来。检查它。您需要将txt传递给ajax函数。如果在您的选择框中选择全部,我可以使用add、separated添加所有值,所以您必须使用ajax页面文件分解、分隔符,然后获取全部values@dummy虚拟检查我的小提琴演示