0
I am working with Node and express and need to fill a table with information that comes from an SQL Database. I run my get code from the page that way:
app.get('/Home.ejs', (req, resp) => {
SQL_Server(Seleciona, (rec) => {
resp.render("Home", { Objeto: rec });
resp.end();
});
});
It was working when I was carrying the tabel like this:
<% for(var i = 0; i < Objeto.length; i++){ %>
<tr>
<td name="Nome">
<%=Objeto[i].ObjetoNome %>
</td>
<td name="Nome">
<%=Objeto[i].ObjetoEndereco %>
</td>
</tr>
<%}%>
But now I need to fill this table using Jquery, because we are standardizing the templates of all systems. When I tried using jquery datatable, it is no longer displaying the table. Here is my code:
var TableDados = $('#MinhaTabela').DataTable({
"serverSide": true,
ajax: {
"url": "/Home.ejs",
"dataSrc": "Objeto"
},
"scrollX": true,
"processing": true,
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"deferRender": true,
"language":
{
"url": "<% /scripts/plugins / dataTables / languagePT - BR.json' %>"
},
"columns": [
{ "data": "Nome" },
{ "data": "Endereço" },
],
"order": [0, "asc"]
});
It no longer opens the screen and displays the message:
Error: Can’t set headers after they are sent. At Serverresponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
I researched several solutions and examples but keeps displaying this error.