Node.js 将post保存到数据库后,如何路由到另一个ejs页面

Node.js 将post保存到数据库后,如何路由到另一个ejs页面,node.js,ajax,express,redirect,ejs,Node.js,Ajax,Express,Redirect,Ejs,如何在node.js和ejs中的帖子之后加载另一个页面 //router function router() { ticketRouter.route("/create/submit") // tied to submit from one ejs .post(dataControllerThatTakesCareOfThis) // works fine // either in here, or even the controller I suppose I wa

如何在node.js和ejs中的帖子之后加载另一个页面

//router
function router() {
   ticketRouter.route("/create/submit") // tied to submit from one ejs
      .post(dataControllerThatTakesCareOfThis) // works fine

    // either in here, or even the controller I suppose I want to load another page after the submit takes place?
     res.redirect(200, '/load:postSubmit') // doesn't work
     res.send({ redirect: '/load:postSubmit' }) // great for ajax response only

}

module.exports = router;
那么,您是否可以在node.js中执行上述操作,而不必返回客户机并提供一些信息,然后让客户机提问以处理这些信息?是否有一种“重定向”或一种方式可以像这样路由响应


谢谢

假设您使用的是ExpressJS,EJS是您的模板引擎:

您应该处理重定向到DataControllerTakesCarlofThis函数的过程

这两条线:

无法工作,因为他们正在使用res对象,该对象未在此处定义,但在路由器对象的Post方法的回调中


更多信息请参见

我对你在这里写的内容感到非常困惑。您正在调用'res.redirect'和'res.send',但您不在express中间件或http回调中。你真的展示了完整正确的代码吗?不,这不是完整的代码,而是我正在尝试的一个例子。一般来说,我只是询问post的处理程序(路由、控制器)是否可以转发到另一个路由处理程序,而不是像ajax那样将响应发送回客户端,这样就可以掉头请求另一个页面。如果不清楚,我道歉。有意思。因此,该函数是路由器要利用的控制器函数,我尝试了res.redirect(200,url)到那里,但它似乎打印出OK,posting to:/load:postSubmit作为文本响应这是答案,因为我怀疑这种方法是错误的。我需要链接中间件回调并使用next()。谢谢
// either in here, or even the controller I suppose I want to load another page after the submit takes place?
 res.redirect(200, '/load:postSubmit') // doesn't work
 res.send({ redirect: '/load:postSubmit' }) // great for ajax response only