简体   繁体   English

在Ajax中,我希望具有2个或更多输入功能。 我怎样才能做到这一点?

[英]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.

相关问题 错误:不是函数。 我该如何解决? - Error : is not a function. How can I fix it? 假设我有这个javascript函数。 如何将元素传递给它? - Suppose I have this javascript function. How do I pass the element to it? 我如何从此Firebase集合查询功能中获取“ retArr”数组。 我想将数组值用于其他功能 - How do i get the “retArr” array out from this firebase collection query function. I want the array values to used for another function 我如何运行此函数,我想在输入中提供数据,然后将其传递给函数,所以我可以正确地做到这一点吗? - how can i run this function i want to provide data in the input then pass it into function so do i do it properly? 我有一个调用PHP函数的JavaScript函数。 如何将结果显示在html中而不显示在警报框中? - I have a JavaScript function that calls a PHP Function. How can I get the results to display in the html and not in an alert box? 在Marklogic中,我有一个自定义JavaScript函数。 如何通过REST API调用它? 从CURL调用它的过程是什么? - In Marklogic, I have a custom JavaScript function. How do I call it through REST API? What is the process of calling it from CURL? 我想使用模式,但我只是继续获得$(…).modal不是函数。 我已经按照正确的顺序使用了jquery和bootstrap js - i want to use modal but i just keep on getting $(…).modal is not a function. I have used jquery and bootstrap js in proper order 2 个或更多具有相同功能的按钮。 如何? - 2 or more buttons which have both the same function. How? 如何避免 [Vue 警告]:您可能在组件渲染 function 中有无限更新循环。 在 VUEJS 中 - How can I avoid [Vue warn]: You may have an infinite update loop in a component render function. in VUEJS 我想使用这个函数在 min 和 max 之间生成一个随机偶数。 我需要在此功能中更改什么? - I want to generate a random even number between min and max using this function. What do i need to change in this function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM