【发布时间】:2011-10-21 19:06:19
【问题描述】:
我正在尝试从 php 文件中获取一些自动完成功能,但效果不佳..
这是 html 文件:
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
这是脚本
<script>
$(function() {
$( "#tags" ).autocomplete({
source: "test.php",
autoFocus : true,
dataType: "json"
});
});
</script>
还有 test.php 文件:
<?
$term = $_REQUEST['term'];
$result = array();
$arr['id'] = "pippo";
$arr['value'] = "pippo";
array_push($result, $arr);
$arr['id'] = "topo";
$arr['value'] = "topo";
array_push($result, $arr);
echo json_encode($result);
?>
为什么我输入 T 我会同时得到 topo 和 pippo?
【问题讨论】:
-
您的远程数据源(PHP 代码)应该只返回与
term请求变量匹配的项目,而不是全部。