【发布时间】:2013-09-24 11:58:49
【问题描述】:
我想自动完成并从数据库中获取数据
这是我的代码:
<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 );
}
?>
我看不到任何建议,请帮我看看错误在哪里?
【问题讨论】:
-
源是自动建议的数组而不是 php 页面...你需要在页面加载时进行 ajax 加载然后将其放入数组中使用源中的数组然后它会起作用..检查一次 jqueryui.com/autocomplete
-
@nickle that is not true API 表明您可以有一个指向将返回 JSON 的资源的字符串
标签: javascript php jquery json autocomplete