How to make another ajax call upon selection of autocomplete text field value in ASP.NET MVC 4?

喜欢而已 提交于 2019-11-29 12:54:26

You can do that in the select event of the autocomplete.

$(function () {
    var src = '@Url.Action("GetParts", "Parts")'
    $("#autoCompleteBox").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: src,
                async: true,
                dataType: "json",
                data: {
                    partNumber: $("#autoCompleteBox").val()
                },
                success: function (data) {
                    response(data[0]);
                }
            });
        },
        select: function (event, ui) {
           var item= ui.item.label;
           //Now make the ajax call here
           $.post("SomeValidUrl", new { id : item } ,function(res){
               // do something with res
           });
        }
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!