Fill table in nodejs (jade) of an sql query

0

I have this query

getAnalisisDetallado: function(req, res, next) {

        var config = require('.././database/config');
        // connect to your database
        sql.connect(config, function(err) {

            if (err) console.log(err);

            // create Request object
            var request = new sql.Request();

            // query to the database and get the records
            request.query('SELECT SI_Articulo, SI_UM, SI_Ubicacion FROM SI_Inventario_Teorico_QAD', function(err, rows, recordset) {

                if (err) console.log(err)

                // send records as a response
                res.send(recordset);
            return res.render('menu/analisisDetallado', { title: 'Users', rows: rows });
            sql.close();
            });
        });


    }

Which brings me some data from the database and what I should do is insert it into a table

div(class="container aDetallado")
    div(class="row center span10")
      table(id="test-table" class="table table-striped table-hover table-condensed")
        thead
          tr
            th Articulo
              i(class="icon-filter editable editable-click editable-empty")
            th Um
              i(class="icon-filter editable editable-click editable-empty")
            th #Ubic
              i(class="icon-filter editable editable-click editable-empty")
        tbody
           each item in rows
            tr
              td= item.SI_Articulo
              td= item.SI_UM
              td= item.SI_Ubicacion

and I get the following error Error Can´t set headers after they are sent I do not know why that headers error will be.

    
asked by Eduard 21.06.2017 в 22:59
source

2 answers

1

What I usually do is render the view and pass the parameters to him in the following way:

res.render('carpeta/vista', {
           title: 'Titulo de la vista',
           data: JSON.parse(rows)
         });
    
answered by 22.06.2017 / 16:25
source
0

You are sending two responses for a single request:

  

Error Can't set headers after they are send

Since you do this:

res.send(recordset); // ¿para qué es esto?
return res.render('menu/analisisDetallado', { title: 'Users', rows: rows });

Both res.send and res.render are HTTP responses that you are sending for a single request. It does not make sense to use both; or send the data as json or render a view with the data.

    
answered by 22.06.2017 в 16:35