如何在Node.js Express中的app.post('/deletemsg')中调用app.post('/deletemsg') [英] How to call app.post('/deletemsg') inside app.post('/deletemsg') in nodejs express

查看:29
本文介绍了如何在Node.js Express中的app.post('/deletemsg')中调用app.post('/deletemsg')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我..我是nodejs的新手..如何在另一条路由内调用一条路由.在getmsg路由中进行一些查询以及第一个调用文本路由deletemsg的结果.

Anyone help me..I am new in nodejs ..how to call one route inside another route.doing some query in getmsg route and result of the first one calling text route deletemsg..

app.post('/getmsg', function (req, res) {
  app.post('/deletemsg',{id:2});//need to call this 
}
app.post('/deletemsg', function (req, res) { //do something
}

推荐答案

如果您要使用app.post删除列,我认为这不是个绝招.您需要发送带有body对象的id,得到的外观如下

i think this is not a gud trick if you want to delete column with app.post you need to send id with body object the get look like this

$http.post('/getmsg',{id:2})
 .success(function(success){
  //do  someting with success response
  })
 .error(function(err){
 //do somthing with err response
 })

和服务器应该是这样的(如

and server should be like this (as NoDownvotesPlz suggests):

app.post('/getmsg', function (req, res) {
 var id  = req.body.id;
 getCalled(req,res,id);//pass req, res and the object you want to send
}

app.post('/deletemsg',getCalled)  // pass function here

function getCalled(req, res, obj) { 

//do something
}

这篇关于如何在Node.js Express中的app.post('/deletemsg')中调用app.post('/deletemsg')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆