代码之家  ›  专栏  ›  技术社区  ›  Roman Roshchuk

有没有从ejs到node js服务器获取抓取内容的方法?

  •  -2
  • Roman Roshchuk  · 技术社区  · 6 年前

    我有一个ejs页面,它在表单中有很多输入。有没有办法从ejs页面获取这些输入并将它们传递回服务器? 我知道如何通过服务器将变量传递到ejs页面,但是否有相反的方法?基本上,我在问是否有一种方法可以从客户机传递到服务器。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Rouzbeh Hz    6 年前

    您可以使用express+body解析器创建post api:

    router.post('/myapi', (req, res) => {
      // Do some stuff with the req body data
      name: req.body.name,
      email: req.body.email,
      otherStuff: req.body.stuff
    }