【发布时间】:2020-01-29 05:25:53
【问题描述】:
我使用res.write() 方法向客户端发送html 文件。我还想发送一个object 附加到这个html。
我尝试stringify 那个对象并像我写html 文件一样写它,但是当我这样做时,我的字符串化json object 仍然在html 之外。我需要那个json对象在html里面,所以我可以用客户端js文件解析它。
我应该如何解决这个问题?
我尝试将其作为Json object 发送。但我无法通过html 获得它。
app.get('/uniform', (req,res) => {
fs.readFile('uniformflowindex.html', function(err, data) {
var channelobj = JSON.stringify(channel);
res.write(data);
res.write("<div id='objectstring'>" + channelobj + "</div>");
res.end('');
});
});
它给出了输出:
<html>
...
my html file
...
</html>
<div id='objectstring'>{"_events":{},"_eventsCount":0,"Discharge":20,"FlowDepth":5.......}</div>
我只希望这个div 出现在html 文件中..
【问题讨论】:
标签: javascript html node.js json express