How can I use JSON data to populate the options of a select box?

后端 未结 6 2244
情歌与酒
情歌与酒 2020-11-28 04:25

I need to feed cities based on country of selection. I did it programmically but have no idea how to put JSON data into the select box. I tried several ways using jQuery, bu

6条回答
  •  悲哀的现实
    2020-11-28 05:15

    Given returned json from your://site.com:

    [{text:"Text1", val:"Value1"},
    {text:"Text2", val:"Value2"},
    {text:"Text3", val:"Value3"}]
    

    Use this:

        $.getJSON("your://site.com", function(json){
                $('#select').empty();
                $('#select').append($('

提交回复
热议问题