【发布时间】:2017-03-21 21:35:39
【问题描述】:
在 index.html 中,我有一个带有 action="/results" 的搜索表单。服务器端我有这个代码:
app.get('/results', function(req, res) {
api.getInfo({query: req.query.searchStr}).then(function(data) {
res.render('results', {title: 'Search Results'}, function(err, html) {
res.send(html);
});
});
});
如果我写res.send(data),那么这些数据就会变成一个字符串并在浏览器中吐出。所以我需要一种方法来发送呈现的 html,但还要将data 放入客户端 javascript。最传统的方法是什么?
【问题讨论】:
标签: javascript html node.js web-development-server