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

后端 未结 1 1286
囚心锁ツ
囚心锁ツ 2020-12-20 09:16

I have an autocomplete text field, that uses JSON like so:

          $(function () {
              var src = \'@Url.Action(\"GetParts\", \"Parts\")\'
                


        
相关标签:
1条回答
  • 2020-12-20 09:44

    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
               });
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题