简体   繁体   English

从Express发送JSON数据到HTML NodeJS

[英]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.

相关问题 从html发送和接收数据,并使用nodejs表达 - send and recieve data from html and express using nodejs 将JSON数据从Nodejs Express发送到Backbone - Sending JSON data from Nodejs Express to Backbone 使用 nodejs 从 MariaDB 获取数据并将它们发送到 html 页面(Express JS) - Get data from MariaDB with nodejs and send them to an html page (Express JS) 如何从后端(快递)在nodeJS中创建html文件并将其发送到客户端? - How to create and send html file to client in nodeJS from backend(express)? Node.js-如何将数据从HTML发送到HAPI - Nodejs - How to send data from html to hapi 如何将数据从html表发送到nodejs? - How to send data from an html table to nodejs? 从服务器向客户端发送数据。 节点JS,快递 - Send data from server to client. NodeJS, Express 我不知道如何在 nodejs express 服务器中存储来自 api 调用的 json 数据,并将其发送到反应本机客户端 - I do not know how to store json data from an api call within a nodejs express server, and send it to a react native client 使用 nodejs Express 渲染带有数据的 html - Rendering html with data with nodejs Express 无法将数据从字符串解析到 javascript nodejs express 中的 html - Unable to parse the data from string to html in javascript nodejs express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM