开发者

JSON Web service to HTML dropdown

开发者 https://www.devze.com 2023-03-17 06:28 出处:网络
I have a Web service which returns a JSON file, and I开发者_运维问答\'m required to show the data in an HTML dropdown (select). How can I do this with jQuery or any other method?$.getJSON(

I have a Web service which returns a JSON file, and I开发者_运维问答'm required to show the data in an HTML dropdown (select). How can I do this with jQuery or any other method?


$.getJSON(
    "/path/to/service",
    function(data) {

        var $s = $('.your_select_element').empty();

        // the actual contents of this loop will be
        // specific to the data
        for (var k in data) {
            $('<option></option>')
                .val(data[k].value)
                .text(data[k].text)
                .appendTo($s);
        }
    }
)


 $.ajax({
    url: "http://pathto.html",
    dataType: JSON,
    success: function(data){
        $(data).each(function(){
            $("select").append();//Append what you want.
        });
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消