I have the following Ajax
$(function() {
//function ajax
$('#example-table #btn-analisisInterno').click(function(e) {
e.preventDefault();
var elemento = $(this);
var idArt = elemento.parent().parent().find('#id_articulo').text();
console.log(idArt);
$.ajax({
url: 'http://localhost:3000/visualizarArt',
method: 'post',
data: { idArticulo: idArt },
success: function(res) {
console.log(res);
//document.getElementById('artic').innerHTML = id;
$('#example tbody').append("<tr><td>" + res.SI_Articulo + "</td><td>" + res.SI_Existencia + "</td><td>" + res.SI_Ubicacion + "</td></tr>");
}
});
});
});
which makes me a query to sql and brings me the following data in an array
Query
getVisualizarArticulo: function(req, res, next) {
console.log('Entra');
var id = req.body.idArticulo;
var config = require('.././database/config');
console.log(id);
var art = null;
var respuesta = { res: false };
sql.connect(config)
.then(function() {
var request2 = new sql.Request();
request2.query("SELECT SI_Articulo, SI_Ubicacion, SI_Existencia FROM SI_Inventario_Teorico_QAD WHERE SI_Articulo = '" + req.body.idArticulo + "'")
.then(function(recordset) {
art = recordset['recordset'];
console.log('Recordset: ' + recordset);
console.log('Affected: ' + request2.rowsAffected);
const articulos = art;
console.log(articulos);
sql.close();
respuesta.res = true;
res.json(articulos);
})
.catch(function(err) {
console.log('Request error: ' + err);
});
})
.catch(function(err) {
if (err) {
console.log('SQL Connection Error: ' + err);
}
});
}
(5) [{…}, {…}, {…}, {…}, {…}]
0
:
{SI_Articulo: "200002", SI_Ubicacion: "FF1031", SI_Existencia: 28}
1
:
{SI_Articulo: "200002", SI_Ubicacion: "o293534a", SI_Existencia: 11}
2
:
{SI_Articulo: "200002", SI_Ubicacion: "o293894a", SI_Existencia: 16}
3
:
{SI_Articulo: "200002", SI_Ubicacion: "o293894d", SI_Existencia: 17}
4
:
{SI_Articulo: "200002", SI_Ubicacion: "TRANSCLI", SI_Existencia: 1}
This is the information that brings me in console.log(res);
What I'm trying to do is enter that information into an html table and since that table is in a modal every time I consult it, it should be cleaned and the data re-entered.