jquery - display json response from ajax call in html table -
i below json response ajax call:
{"items":[{"name":"mp 201spf_1c","productno":"123","commerceitemqty":1,"price":"$350.00","leaseornot":"false"},{"name":"mp 201spf_1c","productno":"456","commerceitemqty":4,"price":"$1,400.00","leaseornot":"false"},{"name":"mp 201spf_1c","productno":"789","commerceitemqty":4,"price":"$1,400.00","leaseornot":"true"}]}
here code:
$.getjson(ajaxresponse, function (data) { var tr; (var = 0; < data.length; i++) { tr = $('<tr/>'); tr.append("<td><h3>" + data[i].name + "</h3>""<p><strong>" + data[i].productno + "</strong></p>""<div>" + data[i].leaseornot + "</div></td>"); tr.append("<td>" + data[i].commerceitemqty + "</td>"); tr.append("<td>" + data[i].price + "</td>"); $('table').append(tr); } });
i need append above json data table. how can it? please help!
you need iterate on items object array insde items object:
$.each(json.items,function(index,item){ console.log(item); tr = $('<tr/>'); tr.append("<td><h3>" + item.name + "</h3><p><strong>" + item.productno + "</strong></p><div>" + item.leaseornot + "</div></td>"); tr.append("<td>" + item.commerceitemqty + "</td>"); tr.append("<td>" +item.price + "</td>"); $('table').append(tr); })
Comments
Post a Comment