【发布时间】:2016-07-12 10:34:55
【问题描述】:
在以下代码中,我根据用户请求显示以下 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>
在 app.js 内。在这里,我根据用户请求呈现 HTML 文件
app.get('/clubreq', function(req, res, next){
res.render('clubreq', {
title: 'Club Requests',
"clubreq" : docs
});
});
app.post('/clubreq', function(req, res, next){
//I want to access clubname and type datavariables here and store it in my mongodb database
});
【问题讨论】:
-
俱乐部名称和类型变量是在纯文本中呈现还是在文本输入中呈现。另外,app.post() 代码实际上不是客户端,是吗?
-
是的,我希望将这两个变量呈现为纯文本
-
如果您想在提交表单时访问值服务器端,您需要将它们放入输入元素中。您可以选择文本类型或隐藏类型,但除非这些值嵌入到有效的表单字段值中,否则 app.post() 将无法访问它们。
标签: javascript html node.js express ejs