繁体   English   中英

如何使用expressJS在“后”路由器中获得价值?

[英]How can I get value in the “post” router using expressJS?

我在nodejs方面很新鲜,如表所示。

假设我从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);
   });
});

如果要在同一路径中处理GETPOST ,适用于app.all

就像

app.all('/',function(req,res){ 

       //processing code here 

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM