【发布时间】:2016-11-22 19:03:19
【问题描述】:
我目前正在创建一个节点投注应用程序,当我发布到数据库时,我需要重定向回索引页面。目前我的解决方法是呈现 index.hbs 页面,但这将在 mywebsite.com/bet 呈现,这是一个问题。我看过使用 res.redirect() 但问题是我无法携带我的会话信息(用户:req.user)或我希望在页面上呈现的集合项目(项目:doc)
app.post('/bet', function(req, res){
// All betting functionality above and when completed do the following
Collection.find(query).limit(10)
.then(function(doc){
res.render('index', {title: 'MyWebsite | Home', items: doc, user: req.user,
message: req.flash('bet-update')});
});
});
有没有更聪明的方法来让索引页面与相关数据一起呈现?完成后是否可以从 POST 函数中发送 GET 请求?我的 app.get('/') 函数完全符合我的需要,但是当我必须将相同的代码复制并粘贴到 Node 中的每个 POST 请求函数中时,情况就变得一团糟了。
【问题讨论】:
-
嗯.....ajax....
标签: javascript node.js mongodb express