I have the following situation, when I insert data from the database, my table is populated as follows:
Andthismessageappears:"No data available in table", as if the data that is inserted were not for the table.
The HTML code is this:
<table id="dataTable" class="table table-condensed table-hover table-striped table-responsive">
<thead>
<tr>
<th>Código</th>
<th>Nome</th>
<th>CNPJ</th>
<th>E-mail</th>
<th>Responsável</th>
</tr>
</thead>
<tbody></tbody>
</table>
And the java script code is this:
$(document).ready(function() {
$.ajax({
url: 'http://localhost:8080/exemplo',
data: {},
dataType: "json",
cache: false,
success: function (data) {
$.each(data, function (i, val) {
var tr = "<tr>" +
"<td>"+ val.id + "</td>" +
"<td>"+ val.id + "</td>" +
"<td>"+ val.id + "</td>" +
"<td>"+ val.id + "</td>" +
"<td>"+ val.id + "</td>" +
"</tr>";
$(tr).appendTo('tbody');
});
}
});
});
Soon the table functions like pagination and search also do not work. However if I enter the data manually in the HTML between the tbody tags the table works normally. Does anyone know what this is about?
Thanks for the help right away.