Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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
AJAX+PHP数据搜索_Php_Javascript_Mysql_Database_Ajax - Fatal编程技术网

AJAX+PHP数据搜索

AJAX+PHP数据搜索,php,javascript,mysql,database,ajax,Php,Javascript,Mysql,Database,Ajax,我使用下面的代码从我的数据库中提取信息,在选项菜单中,数据会显示出来,但由于某种原因,没有使用ajax传递值来提取信息。请告知 PHP: Ajax.php <?php $q=$_GET["q"]; include("config.php"); //Query $sql = "select `full_name` from `users` where `p_name` = '$q'"; $query = mysql_query($sql) or die ("Error: "

我使用下面的代码从我的数据库中提取信息,在选项菜单中,数据会显示出来,但由于某种原因,没有使用ajax传递值来提取信息。请告知

PHP:

Ajax.php

 <?php
 $q=$_GET["q"];

 include("config.php");


 //Query
 $sql = "select `full_name` from `users` where `p_name` = '$q'";
 $query = mysql_query($sql) or die ("Error: ".mysql_error());

    while ($row = mysql_fetch_array($query)){

 $full_name = $row['Full_name'];


        print $full_name

        ?>

似乎没有在ajax.php中关闭while循环。
代码的其余部分似乎没有问题。

在ajax.php中似乎没有关闭while循环。
代码的其余部分似乎还可以。

现在可以工作了。您的代码中有两个错误。第一个我更正onchange=showUserthis.value;第二个是echo$row['full_name'];} Ajax.php

Index.php

 <html>
 <head>
 <script type="text/javascript">
 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","ajax.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
 <select onchange="showUser(this.value);">
 <option>Select user</option>
 <?php
 include("config.php");
$query="SELECT p_name, full_name FROM users order by p_name asc";
$result=mysql_query($query);
while(list($p_name, $full_name)=mysql_fetch_row($result)) {
echo "<option value=\"".$p_name."\">".$full_name."</option>";
}

?>
</select>
<div id="txtHint"><div>
</body>
</html>
enter code here

现在它开始工作了。您的代码中有两个错误。第一个我更正onchange=showUserthis.value;第二个是echo$row['full_name'];} Ajax.php

Index.php

 <html>
 <head>
 <script type="text/javascript">
 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","ajax.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
 <select onchange="showUser(this.value);">
 <option>Select user</option>
 <?php
 include("config.php");
$query="SELECT p_name, full_name FROM users order by p_name asc";
$result=mysql_query($query);
while(list($p_name, $full_name)=mysql_fetch_row($result)) {
echo "<option value=\"".$p_name."\">".$full_name."</option>";
}

?>
</select>
<div id="txtHint"><div>
</body>
</html>
enter code here

你是说}在$full_名称后面?是的。Php现在必须出现语法错误,并且不能执行您的代码。虽然这样做了,但仍然不起作用。我想我永远也不会明白这个ajax代码!打印后还缺少一个分号。妈的错,我以前没注意到。总之,您的ajax代码可以正常工作。这个问题显然来自ajax.php。你是说}在$full_名称后面?是的。Php现在必须出现语法错误,并且不能执行您的代码。虽然这样做了,但仍然不起作用。我想我永远也不会明白这个ajax代码!打印后还缺少一个分号。妈的错,我以前没注意到。总之,您的ajax代码可以正常工作。这个问题显然来自ajax.php。
 <html>
 <head>
 <script type="text/javascript">
 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","ajax.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
 <select onchange="showUser(this.value);">
 <option>Select user</option>
 <?php
 include("config.php");
$query="SELECT p_name, full_name FROM users order by p_name asc";
$result=mysql_query($query);
while(list($p_name, $full_name)=mysql_fetch_row($result)) {
echo "<option value=\"".$p_name."\">".$full_name."</option>";
}

?>
</select>
<div id="txtHint"><div>
</body>
</html>
enter code here
Jquery Ajax call through data serach from php file  

$('#btnSubmit').click(function() {  


   var name = $('#Name').val();

       $.ajax({  
           type: "POST",  
           url: "search.php",
           data: "name="+ name,  
           success: function(response){ 
            $('#search').html(response);
           }  
       });
  });