开发者

jQuery autocomplete only displays results sometimes?

开发者 https://www.devze.com 2023-04-02 16:34 出处:网络
I have an autocomplete on a textbox, but it only works some of the time and I can\'t figure out why. The method I tell it to call returns a Json object that is a list of peoples names that it retrieve

I have an autocomplete on a textbox, but it only works some of the time and I can't figure out why. The method I tell it to call returns a Json object that is a list of peoples names that it retrieves from active directory. For some reason the autocomplete won't display them after the user types in three or more characters, even if the search returns a list of names.

The code in the view is like this:

<i开发者_运维技巧nput type="text" id="nominee_name" />
    <script type="text/javascript" language="javascript">
    $(function () {
        $('#nominee_name').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/cap/findnames", type: "POST", dataType: "json",
                    data: { searchText: request.term, maxResults: 10 },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.FullName, value: item.FullName, id: item.FullName }
                        }))
                    }
                })
            }
        });
    });
    </script>

So for example, typing "Da" will display a bunch of Dave's in the autocomplete box, but typing "Dave" will display nothing. Any ideas?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号