任何人都帮助我..我是nodejs的新手..如何在另一条路线内调用一条路线。在getmsg路线中进行一些查询,第一条调用文本路线的结果为deletemsg ..
app.post('/getmsg', function (req, res) {
app.post('/deletemsg',{id:2});//need to call this
}
app.post('/deletemsg', function (req, res) { //do something
}
答案 0 :(得分:0)
一个简单的解决方案,在路由/deletemsg
app.post('/getmsg', function (req, res) {
getCalled(req,res,{id:2});//pass req, res and the object you want to send
}
app.post('/deletemsg',getCalled) // pass function here
function getCalled(req, res, obj) {
//do something
}
答案 1 :(得分:0)
我认为如果你想用app.post删除列,这不是一个gud技巧 你需要发送带有body对象的id,看起来像这样
$http.post('/getmsg',{id:2})
.success(function(success){
//do someting with success response
})
.error(function(err){
//do somthing with err response
})
和服务器应该像这样(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
}