I'm having trouble inserting HTML
using ajax
HTML:
<table class="table table-hover">
<thead id="thead">
<tr id="tr-thead">
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
ajax:
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
success: function(data) {
var colunas = data.result[0][1].data[1].length;
var linhas = data.result[0][1].data.length;
for (var x = 0; x <= colunas - 1; x++) {
//aqui eu coloco meu cabeçalho
$("#tr-thead").append('<td>'+data.result[0][0][opcao][x]+'</td>');
}
for (var x = 0; x <= linhas - 1; x++) {
$("#tbody").append('<tr>');
for (var y = 0; y <= colunas - 1; y++) {
//aqui as linhas com os dados
$("#tbody").append('<td>'+data.result[0][1].data[x][y]+'</td>');
}
$("#tbody").append('</tr>');
}
},
error: function() {
console.log("error");
}
});
The problem is that it is not being inserted correctly, type, in tbody
ta by opening and closing the <tr>
tag and then inserting <td>
.
Another thing is that thead
does not appear.