自动完成选择未触发

时间:2014-06-23 10:06:26

标签: javascript jquery razor autocomplete

我的asp.net MVC razor视图中有以下脚本: -

$("#Technology2_Tag").autocomplete({
            minLength: 1, delay: 1000,
            source: function (request, response) {
                $.ajax({
                    url: "@Url.Content("~/Switch/AutoComplete2")",
                    dataType: "json",

                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(),
                    },
                    success: function (data) {
                        response(data);
                    },
                    select: function (event, ui) 
                    {
                        //get the value user selected
                        alert('t');
                        //your code populate data to dropdownlist...
                    }
                });
            },

        });

自动填充功能正常,但选择未激活,例如选择自动填充项目后,是否会显示警告?谁有人建议? 感谢

1 个答案:

答案 0 :(得分:1)

它放在错误的ajax里面,把它放在它外面:

$("#Technology2_Tag").autocomplete({
            minLength: 1, 
            delay: 1000,
            source: function (request, response) {
                $.ajax({
                    url: "@Url.Content("~/Switch/AutoComplete2")",
                    dataType: "json",

                    data: {
                        term: request.term,
                        SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val()
                    },
                    success: function (data) {
                        response(data);
                    }

                }); // <----------ending of ajax 
            }, //<------- ending bracket of source function
            select: function (event, ui) 
                    {
                        //get the value user selected
                        alert('t');
                        //your code populate data to dropdownlist...
                    }

        });