[英]Send JSON data from express to html NodeJS
Hello all i'm new with node so here my use case i want to post data to my express app and show it on a html page is that possible with nodeJs ? 大家好,我是node的新手,所以在这里我想将数据发布到我的express应用程序并在html页面上显示,使用nodeJs是否可行?
Here my code 这是我的代码
app.post('/', function(req, res){
res.sendFile(__dirname + '/views/index.html', {data: req.body});
})
There are many tutorials showing how to do that. 有许多教程显示了如何执行此操作。 I would recommend first you understand how HTTP protocol works (The message structure : https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html ).
我建议您首先了解HTTP协议的工作原理(消息结构: https : //www.w3.org/Protocols/rfc2616/rfc2616-sec4.html )。 Then go dive into node and exchange data through requests and responses.
然后深入节点并通过请求和响应交换数据。 I'd recommend body-parser to arrange the data format between the two sides.
我建议使用body-parser在两侧之间安排数据格式。 Also read the express documentation.
另请阅读快速文档。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.