Jquery autocomplete not showing the desired result

柔情痞子 提交于 2019-12-11 19:59:07

问题


I've this code

 $("#tb1").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "../mycontroller/getdata",
                dataType: "json",
                data: { strText: "" },
                success: function (Data) {
                    response($.map(Data.Data, function (item) {
                        return {
                            label: item.Name,
                            value: item.Id
                        };
                    }));
                }
            });
        },
        minLength: 1,
        select: function (event, ui) {
            alert(ui.item ? "Selected: " + ui.item.label : "Nothing selected, input was " + this.value);
        }
    });

I get the result in textbox, however it shows all the items in list instead of showing seleted items.

For example:- After i enter "ab" in textbox it should display all the items with ab but it shows items with ca, as and other alphabets combinations.

what am i doing wrong, how can i resolve it?


回答1:


Change this:

data: { strText: "" }

to:

data: { strText: $("#tb1").val() }

you are not sending the textbox entered value so it is bringing all records.



来源:https://stackoverflow.com/questions/26098188/jquery-autocomplete-not-showing-the-desired-result

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