简体   繁体   English

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

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

i am fresh in nodejs,so as express. 我在nodejs方面很新鲜,如表所示。

Assuming I'm get the return value from in POST method, how can i get it from GET? 假设我从POST方法中获取返回值,如何从GET中获取返回值? I think, app.use() , I know the middleware can only handler the requests,but at the time, i have not idea. 我认为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);
   });
});

if you want to process GET & POST in the same route, for for app.all 如果要在同一路径中处理GETPOST ,适用于app.all

just like 就像

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

       //processing code here 

});

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

相关问题 在带有express.js的ui-router时如何显示局部信息? - How to get partials to show when using ui-router with expressjs? 当我在 ExpressJS 应用中使用 app.post 时,如何获取自动递增的值? - How to get auto-incremented value when I app.post in ExpressJS app? 如何获取data-id的值,然后使用jquery post将其发布到另一个页面中? - How can I get the value of data-id and post it into another page using jquery post? 如何在 ReactJS + ExpressJS 中将按钮的文本值发送到服务器? - How can I send text value of a button to the server in ReactJS + ExpressJS? 如何获取使用post方法在数据库中插入值的文本框的值? - How can I get value of a text box which is looped using post method to insert value in database? 如何使用ExpressJS访问多个数据库? - How I can access multiple DB using ExpressJS? express.js上的router.get(&#39;/&#39;)不起作用 - router.get('/') on expressjs not working 如何通过在 PHP 中使用 POST 方法获取 style=&quot;display:none&quot; 值 - How can I get style="display:none" value by using POST method in PHP 我如何使用POST / GET将值和下拉菜单的文本发送到另一页 - how can i send value and text of dropdown to another page using POST/GET 如何使用react-router-dom定向链接以呈现填充有prop的常规post组件? - How, using react-router-dom, can I direct a link to render a general post component, populated with props?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM