Loading dynamic data into an ordered- or unordered list cannot be simpler.

First we create a template for each LI row:

var listRow = "<li id=\"{0}\">{1}</li>";

Then we call the ajax method and handle the JSON results:

// Now using my $.stringFormat method
// (see tag 'string format')
// we append the template with the correct values to the ul or ol
$.getJSON("http://somedomain/getsomedata", function(data, status) {
   $.each(data, function() {
   var listRowPopulated = $.stringFormat(listRow, [this.id, this.title]);
      $(listRowPopulated).appendTo("#someul");
    });
});

Leave a Reply