我在login.ejs文件中有一个登陆表单,当我填写完信息后点击提交,如果信息正确会重定向到另一个页面,否则我想在.ejs文件中显示密码错误的提示。以下是详细信息:
这是我的app.js文件代码- 在这里我发送了一个json并隐藏了.ejs文件中的无效密码
app.get('/', function (req, res) {
res.render("login",{Error:"none"});
});
app.post('/login', function (req, res) {
var username = req.body.username;
var password = req.body.password;
//Here will be my code to check detail wrong or right
res.redirect('/',{Error:'block'});
}
这是我登录页面的 login.ejs 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/font.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="Error" id="error" style="display:<%=Error%>;">Invalid email/phone or password</div>
<div class="Body">
<form class="LogBox" action="/login" method="post">
<div class="Head">Log In</div>
<input type="text" placeholder="Email or Phone" class="inputfrontbutton" name="username">
<input type="password" placeholder="Password" class="inputfrontbutton" name="password">
<input type="submit" value="Log In" class="frontsubmit">
</form>
</div>
</body>
</html>
但是我无法在重定向中发送JSON数据。有没有办法可以做到这一点?
Error
没有被传递并显示在你的login.ejs
中吗? - David R