Everything is working fine with the forms post requests I've done so far, but when I try to make an Ajax call I'm not able to deal with it on the server. Although it returns the 'succeed' param, I'm not able to save the information on the database nor make any acions with it on the server.
page.jade:
script
(function () {
$('ul').find('a').on("click", function () {
var option = $(this).data('res');
$('article').animate({ 'margin-left': -600 });
console.log(option + ' ' + #{idn});
var envio = {resultado: option, idupdate: #{idn}};
$.ajax({
url: '/',
type: "post",
data: JSON.stringify(envio),
contentType: 'application/json',
success: function(data) {
console.log('success');
}
});
});
})();
server.js
app.post('/', function (req, res) {
var Resultado = req.body.resultado;
var idUpdate = req.body.idupdate;
if (Resultado == "yes") {
connection.query('UPDATE questions SET yes=yes+1 WHERE id=' + idUpdate + ');');
} else {
connection.query('UPDATE questions SET no=no+1 WHERE id=' + idUpdate + ');');
}
});
I tried to find any similar situation around, but the information on this particular case is scarce. Thanks!!!