javascript - Sails.js : redirection after http delete request -
i start sail.js , don't understand redirection. when post , utilize res.redirect("/articles/") haven't problem.
'post /article': 'articlecontroller.create',
create: function (req, res) { if (!req.param('titre') || !req.param('resume') || !req.param('contenu')) { res.status(400); homecoming res.json(); } else { article.create({ titre: req.param('titre'), resume: req.param('resume'), contenu: req.param('contenu'), url: req.param('titre').replace(/ /g, "-") }).exec(function (err, post) { if (err) { console.log("erreur t_t"); console.log(err); homecoming res.json(err); } else { console.log("article ajouté."); console.log(post); res.redirect("/articles/"); } }); } }
but when it's delete http request have "not found" response :
'delete /article': 'articlecontroller.delete',
delete: function (req, res) { if (!req.param('id')) { res.status(400); homecoming res.json(); } else { article.destroy({ id: req.param('id') }).exec(function (err, article) { if (article.length == 0) { console.log("l'article n'existe pas."); console.log("id = " + req.param('id')); res.status(404); homecoming res.json(); } else { console.log("l'article bien été supprimé"); console.log(article); res.redirect("/articles/"); } }); } },
thanks lot.
edit :
article not null : console.log(article);
but redirection doesn't work : res.redirect("/articles/");
edit 2 : (more details)
console.log("l'article bien été supprimé"); //ok console.log(article); //ok res.redirect("/articles/"); //works in other methode not here
javascript redirect sails.js
No comments:
Post a Comment