【发布时间】:2013-10-16 19:06:35
【问题描述】:
我从 URL:“/accounts/:id/users”获取 JSON 格式的搜索结果,我需要检索该 JSON 数据以呈现“/contacts/find”。 (后一页显示搜索结果。)
这是我的应用路由器。有了这个,我可以在 /contacts/find 中看到 JSON 格式的搜索结果:
app.post('/contacts/find', function(req, res) {
var searchStr = req.param('searchStr', null);
if ( null == searchStr ) {
res.send(400);
return;
}
models.Account.findByString(searchStr, function onSearchDone(err,accounts) {
if (err || accounts.length == 0) {
res.send(404);
} else {
res.send(accounts);
}
});
});
如何使用“帐户”(JSON 格式)并使用帐户信息重新呈现页面?我正在尝试使用下面的代码 sn-p,但它不起作用。
app.get('/contacts/find', function(req, res) {
res.render('searchResult.ejs', {
accounts: req.accounts,
email: req.accounts.email
})
}
app.get 方法不起作用。该 URL 仅显示 JSON 数据。
【问题讨论】:
标签: javascript node.js post express get