Fill in a list with Json's return

1

I wanted to populate a textarea or anything that looks like a list, with the items the guy selects from a dropdow. So I thought so, but I do not know how to feed the list ...

<textarea cols="1" id="lista">
     <ul>

     </ul>
</textarea>

            <script type="text/javascript">
                $(document).ready(function () {
                    $('#Chamada').change(function () {
                        var id = $(Chamada).val();
                        var url = '@Url.Action("MusicaAdc", "Chamada")';
                        $.post(url, { id: id },
                            function (data) {
                                $('#lista').append('<li>"' + value.Nome + '</li>');
                            });
                    });
                });
            </script>
    
asked by anonymous 02.12.2016 / 04:06

1 answer

2

I do not know how your json is, but if all data is returned at a single time you can use one each to scroll through it and add row by row in the value table should return the value within each, if it is one string you use only the value to display, if it is an array use value []

$(document).ready(function () {
     $('#Chamada').change(function () {
          var id = $(Chamada).val();
          var url = '@Url.Action("MusicaAdc", "Chamada")';
          $.post(url, { id: id },
          function (data) {
               $.each(data, function(index, value){
                       $('#lista').append('<li>"' + value["Nome"] + '</li>');
                });
           }
      });
});
    
02.12.2016 / 04:12