How can you convert an array of strings represented in JSON format and convert this to an HTML bulleted list using jQuery?
var ul = $('<ul>').appendTo('body');
var json = { items: ['item 1', 'item 2', 'item 3'] };
$(json.items).each(function(index, item) {
ul.append(
$(document.createElement('li')).text(item)
);
});
As far as fetching the JSON from your server using AJAX is concerned you could use the $.getJSON()
function.
Live demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With