从ExpressJS服务器发送数据以更新我当前HTML表单中的文本



最终,我想从index.js接收POST数据(我已经完成了(,处理它,然后更改从中获取值的字段的值。

例如:

app.post("/", funtion (req, res) {
data = req.body // The data I am getting
// Proccesing it
newdata = "blabla"
res.send("?") // How do I return the data to the input fields I got the values from so the user can see them?
});
<form action="/" method="post">
<input type="text" name="computer" value="">
<input type="text" name="ip" value="">
<input type="submit" value="Button">
</form>

您应该使用res.send((向客户端返回带有值的JSON响应。

res.send({computer:'MyComputer',ip:'192.0.0.1'});

在客户端,您应该接收JSON响应并将其呈现在表单上。

最新更新