JSON Web service to HTML dropdown
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.
});
}
精彩评论