Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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中,我希望有2个或更多的输入函数。我该怎么做?_Javascript_Php_Ajax - Fatal编程技术网

Javascript 在Ajax中,我希望有2个或更多的输入函数。我该怎么做?

Javascript 在Ajax中,我希望有2个或更多的输入函数。我该怎么做?,javascript,php,ajax,Javascript,Php,Ajax,在Ajax中,我希望有2个或更多的输入函数。我该怎么做? 也就是说,通常“q”很流行。但我想在ajax程序中添加“p”参数。 下面是我的html脚本代码 <form> <input type="text" name="FirstName" maxlength="20" onkeyup="showUser(this.value)"> <input type="text" name="LastName" maxlength="20" onkeyup="showUs

在Ajax中,我希望有2个或更多的输入函数。我该怎么做? 也就是说,通常“q”很流行。但我想在ajax程序中添加“p”参数。 下面是我的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>


此处将列出人员信息。 函数showUser(str){ 如果(str.length==0) { document.getElementById(“txtHint1”).innerHTML=“”; 返回; } var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“txtHint1”).innerHTML=xmlhttp.responseText; } } var selectedLang=document.getElementById('lang')。值; xmlhttp.open(“GET”、“ds_hint”+selectedLang+”.php?q=“+str,true”); xmlhttp.open(“GET”、“ds_hint”+selectedLang+”.php?p=“+str,true); xmlhttp.send(); }
在脚本中,添加“xmlhttp.open”(“GET”,“ds_hint”+selectedLang+”.php?p=“+str,true);”以通过“q”参数重新搜索第一个搜索结果

下面是我的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);
 ?>
mysqli_select_db($con,“ajax_演示”); $sql=“从FirstName=”、“$q.”和LastName=”、“$p.”的人员中选择*; $result=mysqli\u查询($con,$sql); 回声“ 名字 姓氏 年龄 家乡 工作 "; while($row=mysqli\u fetch\u数组($result)) { 回声“; 回显“$row['FirstName']”; 回显“$row['LastName']”; 回显“$row['Age']”; 回显“$行[“家乡]”; 回显“$row['Job']”; 回声“; } 回声“; mysqli_close($con); ?> 我认为PHP代码是正常的,但是,脚本代码不足以实现搜索功能。 如何解决我的脚本代码??
请帮帮我。

您的查询字符串应该是

  xmlhttp.open("GET","ds_hint_"+selectedLang+".php?q="+qstr+"&p="+pstr,true);
还有你的php

$q=$_GET['q'];
$p=$_GET['p'];
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM persons WHERE FirstName = '".$q."' and LastName = '".$p."'";
尽管如前所述,这不是针对sql注入的过滤
我个人更喜欢pdo prepared statemants

您有SQL注入漏洞。您需要使用较大的查询字符串发送单个请求。如何使用php代码处理较大的查询字符串,即explode(string,“,”)函数?您的代码是一个非常好的主意。但是,当我把它应用到我的代码中时,它就不起作用了。我不知道为什么。“xmlhttp.open(“GET”、“ds_hint”+selectedLang+”。php?q=“+qstr+”&p=“+pstr,true”);”是否正确??