数据库中的php-ajax数据检索
我是ajax新手,需要帮助从mysql表中检索要显示在搜索框中的数据 我的php表单如下所示数据库中的php-ajax数据检索,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我是ajax新手,需要帮助从mysql表中检索要显示在搜索框中的数据 我的php表单如下所示 <html> <head> <script> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="
<html>
<head>
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
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 (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input name ="search" type="text" size="30" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
</body>
</html>
我想在部分匹配时将此值传递回搜索框。
我走对了吗?您在JS中使用了
GET
,因此无法通过php中的$\u POST
访问变量。在php中将其更改为$\u GET
或$\u REQUEST
,它就会工作。此外,您的参数是q
,而不是search
您正在JS中使用GET
,因此在php中无法通过$\u POST
访问变量。在php中将其更改为$\u GET
或$\u REQUEST
,它就会工作。除此之外,您的参数是q
而不是search
,为什么不尝试使用Jquery而不是javascriptLook for…不要使用不推荐使用且不安全的mysql*函数。自PHP5.5(2013年)起,它们就被弃用,并在PHP7(2015年)中被完全删除。改用MySQLi或PDO。2.如果您使用上面提到的MySQLi或PDO,就可以使用Jquery,而不是javascriptLook…不要使用不推荐使用且不安全的mysql*-函数。自PHP5.5(2013年)起,它们就被弃用,并在PHP7(2015年)中被完全删除。改用MySQLi或PDO。2.您完全可以使用,并且应该真正使用而不是连接查询,如果您使用上述MySQLi或PDO,就可以使用这些查询。
$company_name=mysql_query("SELECT * FROM login
WHERE
(company_name LIKE '" . mysql_real_escape_string($_POST['search']) . "')");
$row = mysql_fetch_assoc($company_name);
$name = $row['company_name'];