i am fresh in nodejs,so as express.
Assuming I'm get the return value from in POST method, how can i get it from GET? I think, app.use() , I know the middleware can only handler the requests,but at the time, i have not idea.
...
var Some = require('./Some');
app.get('/',function(req,res){
res.render({
title:"hi",
output: data || '' <--------I wanna get data from below
})
});
app.post('/',function(req,res){
var some = new Some();
some.postOriginCode(code,function(data){
data <-------- here is the data i want.
//I can do it the way,but I don't like.
res.render('index', {output:data});
});
});
...
var Some = require('./Some');
app.get('/',function(req,res){
res.render({
title:"hi",
output:app.get('data')
})
});
app.post('/',function(req,res){
var some = new Some();
some.postOriginCode(code,function(data){
app.set('data',data);
});
});
if you want to process GET
& POST
in the same route, for for app.all
just like
app.all('/',function(req,res){
//processing code here
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.