通过php和jquery在php中创建动态搜索
我想制作动态搜索框,这是我的代码,但它不起作用?我不知道我的问题出在哪里。我使用的代码来自youtube视频中的一个网站,效果很好。我使用了它,但它不起作用。 请帮帮我通过php和jquery在php中创建动态搜索,php,jquery,ajax,search,dynamic,Php,Jquery,Ajax,Search,Dynamic,我想制作动态搜索框,这是我的代码,但它不起作用?我不知道我的问题出在哪里。我使用的代码来自youtube视频中的一个网站,效果很好。我使用了它,但它不起作用。 请帮帮我 index.php <div> <input type="text" name="search_customer" id="search_customer" > </div> <div id=&
index.php
<div>
<input type="text" name="search_customer" id="search_customer" >
</div>
<div id="result_customer">
</div>
<script>
$(document).ready(function (){
$('#search_customer').onkeyup(function (){
$txt=$(this).val();
if (txt!='')
{
$.ajax({
url:"action.php",
method:"POST",
data:{search1:txt}
dataType:"text"
success:function(data)
{
$('#result_customer').html(data);
}
});
}else
{
$('#result_customer').html('');
}
}) ;
});
</script>
这是action.php
$Name=$_POST['search1'];
$output='';
$sql = "SELECT * FROM customers where name_customers like'$Name%'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
$output .= '<div >
<table>
<tr>
<th>id</th>
<th>name</th>
</tr>';
while ($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['name_customers']."'>";
$output .= '<tr>
<td>'.$row["id"].'</td>
<td>'.$row["name_customers"].'</td>
</tr>';
}
$output.='</table></div>';
echo $output;
} else {
echo "Data not found";
}
我的问题在哪里?您有输入错误,即:$txt!=txt您有输入错误,即:$txt!=文本