I am getting my search result as JSON format from the URL: "/accounts/:id/users" and I need to retrieve that JSON data to render "/contacts/find". (The latter page shows search results.)
Here is my app router. With this I could see the result of the search in /contacts/find in JSON format:
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);
}
});
});
How can I use "accounts" (in JSON format) and re-render the page with the account info? I am trying with the below code snippet, but it does not work.
app.get('/contacts/find', function(req, res) {
res.render('searchResult.ejs', {
accounts: req.accounts,
email: req.accounts.email
})
}
The app.get method is not working. The URL just shows JSON data.
So
accounts
is a JSON string? In that case, you can parse it (to convert it back to an object) and pass the result to your template: