'how to send variable along with the redirection in nodejs?
#Following in my code for redirect along with variable in nodejs
app.post("/newcall", function(req, res) {
var f = (req.body.try);
console.log("val"+ f)
res.sendFile(path.join(__dirname, "www/newcall.html"+f))
});
Variable F contain data hello
But by doing this I am getting this error in my console
no such file or directory, stat'c\User\Asus\Desktop\Web\www\newcall\hello
Can you tell ?what Am I missing In this code??Thanks
Solution 1:[1]
Old Issue and GPack answered in comments already that the file in question does not seem to exist (nothing wrong with code above),
however I arrived here due to the title "How to send a variable along with the redirection in node js" and have since discovered the answer to my problem.
If someone ends up here for same reasons as I do then my problem was that I was using
res.redirect instead of res.render("galleryfocus", { image: image });
app.post("/galleryfocus", function(req, res) {
var image = req.body.imageName;
console.log("image is:", image);
res.render("galleryfocus", {
image: image
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Arkadiusz Kulpa |