Answer the question
In order to leave comments, you need to log in
How to create an HTML table with javascript?
I'm trying to create a table in jquery with data received from the server in json format
var a = ['id', 'user_id', 'result', 'date_time']
var trHTML = '';
$.each(response, function (i, x) {
trHTML += '<tr><td>' + x['id'] + '</td><td>' + x['user_id'] + '</td><td>' + x['result'] + '</td><td>'+x['date_time']+'</td></tr>';
});
$('table').append(trHTML);
Answer the question
In order to leave comments, you need to log in
var response = [{
id: 1,
user_id: 2,
result: 'test',
date_time: '123'
}],
trHTML = '';
$.each(response, function (i, x) {
trHTML += '<tr>'
for (res in x) {
trHTML += '<td>' + x[res] + '</td>';
}
trHTML += '</tr>';
});
$('table').append(trHTML);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question