Very nice people ... I am with a small problem in which I am breaking my head ... I am working with node.js and mongodb ... I have a table with several records with different ids ie each record has its id own in which it is already assigned as a fixed number, the idea is to be able to count those records and divide them by their corresponding id ... I am using this code for server side ...
routerApi.get("/contarvotos", function(req, res, next) {
Candidatos.countDocuments({ idcandidato: 25 }, function(error, response) {
if (error) return res.status(500).send(error);
res.status(200).jsonp( [{ idcandidato: 25}], [{ idcandidato: 50}], [{ idcandidato: 75}], [{ idcandidato: 70}])
});
});
and this client side code .. it must be clear that I need to redirect myself to another page ... ajax code
$(function(){
$('#boton').on('click', function(e){
$.ajax({
type: "GET",
url:"/api/votos/contarvotos?",
success: function(response,idcandidato) {
$("#idcandidato").html(resp.idcandidato);
},
error: function(jqXHR, status, error) { //si hay algún error entra acá
}
})
})
})