我有生成以下json数据的php文件
["Health Infoway","Canada Health Infoway","Infowiki","Info",......"Canada"]我在使用上述数据加载自动完成文本框时遇到问题。
下面是我的jquery sript,它调用getorgname.php来获取上述数据
$("input[name=profileOrg]").keyup(function(){
$( "input[name=profileOrg]" ).autocomplete({
source: function(request, response) {
$.getJSON('CHI_custom/customScripts/getorgname.php','user=' + $('#hiddenUser').val(), function(data){
response($.map(data, function(item) {
return item;
}));
}
}
}); });下面是生成json数据的getorgname.php文件
$User = DekiUser::getCurrent();
if($User->isAnonymous() || $User->getUserName() != $_REQUEST['user'])
{
scriptError("Inappropriate access");
}else{
$ds = my_ldap_connect(CHI_LDAP_LOCATION, CHI_LDAP_PORT, CHI_LDAP_USE_TLS);
$groups = get_all_groups($ds, CHI_LDAP_BASE_DN, CHI_LDAP_BIND_DIRECTORY, CHI_LDAP_BIND_PASSWORD);
$sr = @ldap_search($ds, "ou=people,".CHI_LDAP_BASE_DN, "(uid=*)");
$nt = ldap_get_entries( $ds, $sr );
foreach( $nt as $each )
{
if( is_array( $each ) )
{
$json[] = $each['o'][0];
}
}
}
echo json_encode( $json );我正在使用下面的jquery文件自动完成文本框
<script type="text/javascript" src="CHI_custom/customScripts/jquery.formwizard-3.0.5/js/jquery.min.js"></script>
<script type="text/javascript" src="CHI_custom/customScripts/jquery.formwizard-3.0.5/js/jquery-ui.min.js"></script>如何在自动完成文本框中显示这些json数据?
发布于 2013-03-05 00:59:06
更改代码,如下所示:
$.getJSON('CHI_custom/customScripts/getorgname.php','user=' + $('#hiddenUser').val(), function(data){
$("input[name=profileOrg]").autocomplete({
source: data
});
});并且不需要将此代码包装在keyup事件中。所以把那个去掉。
这将解决您的问题。
https://stackoverflow.com/questions/15206592
复制相似问题