0

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?

1

2 Answers 2

4
$.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);
        }
    }
)
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

jimbojw version is correct, I just grabbed the closet code i had that would get it done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.