I have JSOn data coming from my Function, i do not need all the data and had to create some data too based upon the data i am getting, There are many code outlying which specify how can i loop over json data and display it
$.ajax({url: 'page.php',
data: {id: 1},
dataType: 'json',
type:'POST',
success: function (json) {
div.html('<table align="left" width="70%" class="table table-striped borderless p-l-xl">'+
'<tr>'+
'<td>d1</td><td>d2</td><td>Action</td></tr>'+
'<tr><td>'+json.d1+'</td><td>'+json.d2+'</td>'+
'<td><a href="javascript:;" class="t" data-id="'+ json.id +'" data-sid="'+json.sid+'">Delete</a></td>'+
'</tr>'+
'</table>').removeClass('loading');
}
});
Tried using this code
How to iterate JSON object with jQuery
but i am confused how i feed my own href with custom data and separate headers
Did a Small Update
$.each(json,function(index,item){
$('<table><tr>').append(
$("<td>").text(item.d1),
$("<td>").text(item.d2),
$("<td>").html('<a href="javascript:;" class="d" data-sid="'+ json.id+'" data-id="'+json.id+'">Delete</a></td>')
).appendTo(div);
});
now it works and create a seperate for each record, amd missing headers
while i want that all the rows should be under one TABLE Tag and have headers