Reputation: 1328
Hey guys just started with nodejs and express so i came up with the situation where i want to send my data to my GET req from my POST req.Here is the code below for you to understand
app.post('/run-time',(req,res)=>{
const stoptime=req.body.stop
const plannedtime=req.body.planned
const runtime=plannedtime-stoptime
res.redirect('/run-time')
})
this is my POST req where i fetched the values from the form and then calculated the 'runtime' now then i have to redirect to specific GET route
app.get('/run-time',(req,res)=>{
})
so what i want is send the 'runtime' variable calulated in my POST req to my GET req here ..how can i do this ?
Upvotes: 0
Views: 126
Reputation: 63
I've never been use that way But I think you can use querystring querystring can contains data in url.
app.post('/run-time',(req,res)=>{
const stoptime=req.body.stop
const plannedtime=req.body.planned
const runtime=plannedtime-stoptime
res.redirect(`/run-time?runtime={runtime}`);
})
app.get('/run-time',(req,res)=>{
var runtime = req.query.runtime;
//~
})
I think that way can be your solution. But you have to change your code because It is not used like this. Maybe many solution is.
Upvotes: 1