小编Sat*_*tra的帖子

使用 express 时如何访问表单中的 ejs 数据

在以下代码中,我根据用户请求显示以下 HTML 文件。我还想在我的 app.js 文件中访问我的 app.post() 函数中的俱乐部名称和类型数据值。

<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<% include templates/adminheader.ejs %>
<h1>Respond to Club Requests</h1>

<form name="clubform" method="post">
    <% for (var i in clubreq){%>
        Club Name:<%= clubreq[i].clubname %><br><br>//I want to access this variable in my app.post() function
        Club Type:<%= clubreq[i].type %><br><br>
        <input type="submit" value="accept"/><br><br><hr>
    <%} %>
</form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

app.js里面。在这里,我根据用户请求呈现 HTML 文件

app.get('/clubreq', function(req, res, next){
        res.render('clubreq', {
            title: 'Club Requests',
            "clubreq" : docs
        }); …
Run Code Online (Sandbox Code Playgroud)

html javascript ejs node.js express

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

ejs ×1

express ×1

html ×1

javascript ×1

node.js ×1