如何使用expressJS在“post”路由器中获得价值?
我在nodejs中是新鲜的,所以如此expression。
假设我从POST方法获得返回值,我怎么能从GET获取? 我认为, app.use() ,我知道中间件只能处理请求,但在当时,我不知道。
... 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); }); });
如果你想在同一条路线上处理GET
& POST
,则为app.all
就像
app.all('/',function(req,res){ //processing code here });
- 与Express和Redis的asynchronous通话
- $ .getJSON得到一个错误的URL和 404错误,它是怎么发生的?
- 使用socket.io将应用程序连接到节点服务器
- SyntaxError:意外的标记函数 – asynchronous等待Nodejs
- 中间件arrays和组合中间件之间的区别?
- express3-handlebars和18next-node – 基于页面的国际化?
- Node.js / express – 使用redis的护照,获得未授权的会话
- 我在哪里把数据库连接信息在Node.js应用程序?
- unit testingExpress / Loopback中间件,无需启动服务器