gpt4 book ai didi

php - AJAX + PHP 数据搜索

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:21 25 4
gpt4 key购买 nike

我正在使用下面的代码从我的数据库中提取信息,在选项菜单中,数据显示但由于某种原因,该值没有被传递以使用 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="display_data(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>

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

?>

最佳答案

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);
}
});
});

关于php - AJAX + PHP 数据搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4774078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com