Node server with express -使用res.send({})将动态html注入index.html.



我有一个虚拟节点js服务器与快车,我正在暴露一个虚拟的Index.html上,我有一个简单的形式,如:

<form action="/results" method="post" enctype="multipart/form-data">
<input type="text" name="username" placeholder="Full Name" />
<input type="text" name="email" placeholder="Email" />
<input type="file" name="picture" />
<input type="submit" name="submit"value="picture" />
</form>

当表单提交时,我正在做post:

app.post("/results"), function (req, res, next) { }

而不是执行经典的res.send():

res.send(`
some html with updated data 
`)

我只是想动态地更新/注入Index.html元素,而不需要创建一个新的html模板,并添加Hi <span>${req.body.username}</span> <i>your profile image was updated</i>

可能吗?

如果你想传递参数给你的模板,你有多个选项,请看下面这篇文章:https://stackoverflow.com/a/46722250/16956436

最新更新