在node.js中重定向时如何将数据从express传递到.ejs文件 [英] How to pass Data from express to .ejs file while redirecting in node.js
本文介绍了在node.js中重定向时如何将数据从express传递到.ejs文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在填写信息后单击提交时在login.ejs文件中登录表单,如果详细信息正确,则将重定向到页面,否则我想在.ejs中显示密码错误的信息.以下是详细信息
I have on login form in login.ejs file when i click on submit after filling information i am redirecting to the page if detail are correct otherwise i want to show something in .ejs that password is wrong.Below are the detail
这是我的app.js文件代码-在这里,我发送一个json并将该无效密码隐藏在.ejs文件中
Here is my app.js file code- Here i am sending one json and hiding that invalid password in .ejs file
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文件
Here is my login.ejs file
<!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数据.有什么办法可以做到这一点?
But I am unable to send json data in redirect.Is there any way i can do this?
推荐答案
查看全文