Render Json data to HTML

Hi Guys today i will demonstrate how to render the Json data to ui.
    url: ‘/echo/json/’,
    type: “post”,
    dataType: “json”,
    data: {
        json: JSON.stringify([
            id: 1,
            firstName: “Peter”,
            lastName: “Jhons”},
            id: 2,
            firstName: “David”,
            lastName: “Bowie”}
        delay: 3
    success: function(data, textStatus, jqXHR) {
        // since we are using jQuery, you don’t need to parse response
/**iterates json array*** /
function drawTable(data) {
    for (var i = 0; i < data.length; i++) {
/**print json object on ui**/
function drawRow(rowData) {
    var row = $(“<tr />”)
    $(“#personDataTable”).append(row); //this will append tr element to table… keep its reference for a while since we will add cels into it
    row.append($(“<td>” + + “</td>”));
    row.append($(“<td>” + rowData.firstName + “</td>”));
    row.append($(“<td>” + rowData.lastName + “</td>”));
UI Part
<table id=”personDataTable”>
        <th>First Name</th>
        <th>Last Name</th>

Leave a Reply

Your email address will not be published. Required fields are marked *