I have developed a rest api in node js with a get endpoint that, based on a received parameter, returns some data. I'm consuming the api from jquery, but I can't send it that parameter it needs in the get request I make. If I make the request from Postman, it works perfectly for me. This is the endpoint code:
async function getIncidentsByState(req,res){
const params = req.body;
const completed = params.completed;
const idIncident = params.id;
console.log(completed);
try {
const incidents = await Incident.find({completed:completed}).sort({create_at:1});
if(!incidents){
res.status(400).send({msg:"Error al obtener las incidencias"});
}
else{
res.status(200).send(incidents);
}
} catch (error) {
res.status(500).send(error);
}
}
The jquery code that make the request is this:
$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json",
data: {
"completed":false
},
url: "http://localhost:3600/api/getIncidentsByState",
success: function(data){
mostrarIncidencias(data);
}
});
The parameter is not reaching the api and endpoint is printing undefined.
I've tried dozens of different ways,im desesperated.
I would appreciate suggestions on what is going on.
Thanks in advance