In an HTML page called "history.html", I have a form with the POST method that I submit to NodeJS server to make some operations.
<form action="/history/find" method="POST">
some form stuff
</form>
This is the code on the server that receives the form and makes some operations:
router.post("/history/find", function (req, res) {
var fechaInicial = req.body.fechaInicial;
var fechaFinal = req.body.fechaFinal;
var contaminante = req.body.contaminante;
Comment.find(
{
"data.time.s": {
"$gte": fechaInicial,
"$lte": fechaFinal
}
},
{
[contaminante]: 1,
"data.time.s": 1,
"_id": 0
}, function (error, datos) {
res.send(datos);
});
});
The resulting output of this particular Find operation is an set of many JSON objects (they are not surrounded with square brackets like in an Array), in this example, I just put 2 of them:
{
"data": {
"iaqi": {
"co": {
"v": 3.2
}
},
"time": {
"s": "2019-05-14 12:00:00"
}
}
},
{
"data": {
"iaqi": {
"co": {
"v": 4.8
}
},
"time": {
"s": "2019-05-15 00:00:00"
}
}
}
What I need to achieve, is to somehow send back the variable datos that contains the above result, back to the same HTML where I submitted the form.
If I use the res.send(datos), what I get is the data itself represented on the browser. I need to get back to the HTML page but having the variable available to use it and perform other operations directly on the page.
I have been searching the web with no luck on how to do this.
Thank you very much to everyone that can help me with this.