[英]In Ajax, I want to have 2 and more input function. How Can I do this?
In Ajax, I want to have 2 and more input function. 在Ajax中,我希望具有2个或更多输入功能。 How Can I do this?
我怎样才能做到这一点? That is, usually "q" is popular.
也就是说,通常“ q”很流行。 But I want to add "p" parameter in ajax program.
但是我想在ajax程序中添加“ p”参数。 Below is my html-script code.
以下是我的html脚本代码。
<form>
<input type="text" name="FirstName" maxlength="20" onkeyup="showUser(this.value)">
<input type="text" name="LastName" maxlength="20" onkeyup="showUser(this.value)">
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
<script>
function showUser(str){
if (str.length==0)
{
document.getElementById("txtHint1").innerHTML="";
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
}
}
var selectedLang = document.getElementById('lang').value;
xmlhttp.open("GET","ds_hint_"+selectedLang+".php?q="+str,true);
xmlhttp.open("GET","ds_hint_"+selectedLang+".php?p="+str,true);
xmlhttp.send();
}
</script>
In script, "xmlhttp.open("GET","ds_hint_"+selectedLang+".php?p="+str,true);" 在脚本中,“ xmlhttp.open(“ GET”,“ ds_hint _” + selectedLang +“。php?p =” + str,true);“ is added to re-search the first search result by "q" parameter.
添加“ q”参数以重新搜索第一个搜索结果。
So, my php code is below. 因此,我的PHP代码如下。
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM persons WHERE FirstName = '".$q."' and LastName = '".$p."'";
$result = mysqli_query($con,$sql);
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['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Hometown'] . "</td>";
echo "<td>" . $row['Job'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I think PHP code is normal, but, script code is not sufficient for re-search function. 我认为PHP代码是正常的,但是脚本代码不足以提供重新搜索功能。 How can i solve my script code??
我该如何解决我的脚本代码? Please, help me.
请帮我。
your query string should be like 您的查询字符串应类似于
xmlhttp.open("GET","ds_hint_"+selectedLang+".php?q="+qstr+"&p="+pstr,true);
and your php 和你的PHP
$q=$_GET['q'];
$p=$_GET['p'];
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM persons WHERE FirstName = '".$q."' and LastName = '".$p."'";
though as pointed out this is not filtering for sql injection I personally prefer pdo prepared statemants 尽管如前所述,这不是为SQL注入过滤的,但我个人更喜欢pdo准备的statemant
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.