我想自动完成并从数据库中获取数据 这是我的代码:
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(function() {
$( "#tags" ).autocomplete({
source: 'consultation/commande_tags.php'
});
});
</script>
<form method="post" action="#" class="formstyle1">
<input type="type" name="piece_a_commander" id="tags" placeholder="Réference " />
</form>
json页面
<?php
if($_GET["term"]){
include "includes/connexion_bdd.php";
$ref=mysql_real_escape_string($_GET["term"]);
$rq_tags="SELECT * FROM piece WHERE reference_p LIKE '%".$ref."%' ";
$ret_tags=mysql_query($rq_tags) or die (mysql_error());
$array = array();
while ($tab_tags=mysql_fetch_array($ret_tags)){
array_push($array,$tab_tags['reference_p']);
}
echo json_encode($array );
}
?>
我看不出任何建议,请帮我看看错误在哪里?
答案 0 :(得分:0)
试试这段代码:
<强>更换强>
$().ready(function() {
$( "#tags" ).autocomplete("consultation/commande_tags.php", {
width: 108,
matchContains: true,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
});
});
连接:
<?php
$host="localhost";
$user="root";
$pass="";
$bdd="paralel";
// connexion
$con = mysql_connect($host,$user,$pass)or die(mysql_error());
//selection bdd
$ db = mysql_select_db($ bdd,$ con)或die(mysql_error());
?>