使用 node.js 处理表单数据

handle the form data using node.js

这是我的简单 form.html :

<form id="login-form" action=" ?? " method="post">Email
    <br/>
    <input type="text" name="Email" id="em" />
    <br/>password
    <br/>
    <input type="text" name="password" id="pas" />
    <br/>
    <br/>
    <br/>
    <input type="submit" value="Submit" />
</form>

这是我的快递 node.js 代码 app.js:

app.post('/form', passport.authenticate('local-login', {
    failureFlash: true // allow flash messages
}),

function (req, res) {
    console.log("hello");

    if (req.body.remember) {
        req.session.cookie.maxAge = 1000 * 60 * 3;
    } else {
        req.session.cookie.expires = false;
    }
    res.redirect('/');
});

当我在 action 属性中写 app.js path "our-project/app.js" 并提交表单时,没有任何响应。 form.html 路径 "our-project/form/form.html"

和评论区写的差不多:

html 表格的动作部分有点不清楚它的意思是: 我将对这个特定的 URL 路径采取行动。

例如,如果您想从路径“/path”中获取数据,您可以键入 从字面上看,当您使用 get 时,它会更改 URL 上的路径,例如: facebook.com/user=id&name=zargold.

或者,如果您希望它 POST 到达该特定路径...它将: 使用 POST 它将获取该信息...... 那么我可能会使用 npm 模块 body-parser * 这样你就可以轻松地解析来自正文的信息并提取为 body.name 或 body.email.