2011-10-21 79 views
-3

我想从一个PHP文件的一些自动完成,但它不工作不错..的jQuery UI的自动完成功能不能正常工作

这是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我同时得到地形pippo

+3

远程数据源(PHP代码)应该只返回匹配的项目的'长期'请求变量,而不是全部。 –

+0

谢谢你,我做了:) – gaggina

回答

0

因为你告诉服务器返回所有的结果:

$arr['id'] = "pippo"; 
$arr['value'] = "pippo";  
array_push($result, $arr);  
$arr['id'] = "topo";  
$arr['value'] = "topo";  
array_push($result, $arr); 

不仅仅是那些符合