Javascript PHP Live Search没有';不显示结果
我有这个html代码,我想在其中搜索年份和学期:Javascript PHP Live Search没有';不显示结果,javascript,php,mysql,Javascript,Php,Mysql,我有这个html代码,我想在其中搜索年份和学期: <script> function aa() { xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","rankGradePrint.php?nm="+document.form1.t1.value,false); xmlhttp.send(null); document.getElementById("d1").innerHTML=xmlhttp.responseText; } fun
<script>
function aa() {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","rankGradePrint.php?nm="+document.form1.t1.value,false);
xmlhttp.send(null);
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
function bb() {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","rankGradePrint.php?nmm="+document.form2.t2.value,false);
xmlhttp.send(null);
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
</script>
<form name="form1" method="post">
<table width="405px" align="center">
<tr>
<td width="5%"><img src="imgs/icSearch.png" height="25"/></td>
<td><input type="text" name="t1" OnKeyup="aa();" class="box3" placeholder="Year"> </td>
</tr>
</table>
</form>
<form name="form2" method="post">
<table width="405px" align="center">
<tr>
<td width="5%"><img src="imgs/icSearch.png" height="25"/></td>
<td><input type="text" name="t2" OnKeyup="bb();" class="box3" placeholder="Semester"></td>
</tr>
</table>
函数aa(){
xmlhttp=新的XMLHttpRequest();
open(“GET”,“rankGradePrint.php?nm=“+document.form1.t1.value,false”);
xmlhttp.send(空);
document.getElementById(“d1”).innerHTML=xmlhttp.responseText;
}
函数bb(){
xmlhttp=新的XMLHttpRequest();
open(“GET”,“rankGradePrint.php?nmm=“+document.form2.t2.value,false”);
xmlhttp.send(空);
document.getElementById(“d1”).innerHTML=xmlhttp.responseText;
}
这是我的rankGradePrint.php
<?php $nm1=$_GET['nm'];
$nm2=$_GET['nmm'];
if (empty($nm1)){
echo " ";
exit;
}
if (empty($nm2)){
echo " ";
exit;
}
include('konek.php');
$query1="SELECT t2.schoUsername, t2.schoSurname, t2.schoFirstname, t2.schoMiddlename, t1.gradeAve, t1.gradeSem, t1.gradeSender
FROM tblgrade AS t1 JOIN tblscholar AS t2
ON t1.gradeSender=t2.schoUsername
WHERE t1.gYear LIKE ('$nm1%') AND t1.gradeSem LIKE ('$nm2%')
GROUP BY t1.gradeSender ";
$result = mysql_query($query1) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
echo $row['gradeSem'];
echo " - ";
echo $row['schoSurname'] . ", ". $row['schoFirstname'] . " ". $row['schoMiddlename'];
if($row['gradeAve']<='2.5'){
echo '<h1 style="text-decoration:none; color: #f60b3c;"><strong>'. $row['gradeAve'] .'</strong></h1>';
}
else{
echo '<h1 style="text-decoration:none; color: #000510;><strong>'. $row['gradeAve'] .'</strong>';
}
}
?>
<div id="d1"></div>
您可以异步执行请求,但不能使用以下命令:
document.getElementById("d1").innerHTML=xmlhttp.responseText;
相反,您必须指定一个回调:
xmlhttp.onload = function() {
document.getElementById("d1").innerHTML = this.responseText;
};
我建议使用POST
进行搜索:
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST", "/path/to/your/script.php", true);
xmlhttp.onload = function() {
alert(this.responseText);
};
data = new FormData();
data.append('nm', your_value);
xmlhttp.send(data); // could be a form dom node instead
看
我还创建了一个示例来演示它
此外,如前所述,您应该使用MySQLi或PDO,而不是不推荐使用的mysql*
函数。如何向我们显示浏览器错误控制台的输出?您很容易受到sql注入的攻击。而且mysql.*
已被弃用。学习mysqli或pdo。我已经编辑了我的问题。当您使用opera时,使用来检查服务器的输出。@LeRandomGirl您能再试一次吗?我链接了一个jsFiddle来演示它。