【问题标题】:Node server with express - Inject dynamic html into index.html using res.send({})使用 express 的节点服务器 - 使用 res.send({}) 将动态 html 注入 index.html
【发布时间】:2021-12-06 09:56:44
【问题描述】:

我有一个带有 express 的虚拟节点 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>

当表单提交并且我正在发帖时:

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

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

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

我只想动态更新/注入 Index.html 元素,而不创建新的 html 模板并添加类似 Hi &lt;span&gt;${req.body.username}&lt;/span&gt; &lt;i&gt;your profile image was updated&lt;/i&gt; 的内容

这可能吗?

【问题讨论】:

    标签: javascript html node.js express ecmascript-6


    【解决方案1】:

    如果您想将参数传递给您的模板,您有多种选择, 例如看这篇文章: https://stackoverflow.com/a/46722250/16956436

    【讨论】:

    • 这是一个备用想法,但仍然有点初级,我在想动态添加之类的东西
    猜你喜欢
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    相关资源
    最近更新 更多