jQuery UI Autocomplete not populating dropdown

﹥>﹥吖頭↗ 提交于 2019-12-25 14:00:32

问题


Trying to get jquery AutoComplete to return and populate it's dropdown. The input and call looks like this:

<input id="user_login" name="user[login]" size="22" type="text" value="" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">

<script type="text/javascript">
  jQuery(document).ready(function(){
    jQuery('#user_login, #user_group_name').autocomplete({
      source: '/users.js'
    });    
  });
</script>

The URL string that gets called is:

http://localhost:3000/users.js?term=user

The return from users.js looks like this:

[{"id":1802,"login":"some.user"},{"id":3882,"login":"some.other_user"},{"id":2024,"login":"user"}]

The autocomplete seems to interpret some of the return: it populates the autocomplete UL with three LIs, but they are all empty. If I search for something else, the appropriate amount of empty LIs is created. I've verified the JSON return with JSONLint.


回答1:


The problem was with my return. Autocomplete wanted a single item per term, like so:

[{"login":"some.user"}]


来源:https://stackoverflow.com/questions/8762518/jquery-ui-autocomplete-not-populating-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!