Javascript Node.js密码重置
我一直在Node.js和Express.js中进行密码重置 到目前为止,我的代码用于通过电子邮件向用户发送更改密码的信息。此外,用户可以更改密码,并在更改密码后收到电子邮件。 现在,问题是,我提交密码后无法显示成功消息。按下提交按钮后,将重定向到reset.ejs页面。 下面是我的代码 reset.ejsJavascript Node.js密码重置,javascript,node.js,express,forgot-password,Javascript,Node.js,Express,Forgot Password,我一直在Node.js和Express.js中进行密码重置 到目前为止,我的代码用于通过电子邮件向用户发送更改密码的信息。此外,用户可以更改密码,并在更改密码后收到电子邮件。 现在,问题是,我提交密码后无法显示成功消息。按下提交按钮后,将重定向到reset.ejs页面。 下面是我的代码 reset.ejs <html> <body style="margin-left:0px;"> <div class="custom-header">
<html>
<body style="margin-left:0px;">
<div class="custom-header">
<div class="custom-header-left">
</div>
<div class="custom-header-button">
</div>
<div class="custom-header-right">
<a class="navbar-brand">
<img alt="AGD" src="agdlogo.png" style="width:70%; margin-top:-22%;">
</a>
<a class="navbar-brand" href="/"> XXX </a>
<a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</div>
</div>
<!-- Top Bar-->
<div id="fullpage">
<div class="">
<div class="col-md-12 custom-margin-top">
<div class="panel panel-primary text-left">
<div class="panel-heading">Reset your Password</div>
<div class="panel-body">
<div class="col-md-10 ">
<form id="resetpass" role="form" class="form">
<div>
<div class="form-group">
<label for="InputEmail">New Password</label>
<input type="password" class="form-control" id="password" class="password" name="password" placeholder="Enter Email" required>
<label for="InputEmail">Confirm Password</label>
<input type="password" class="form-control" id="repass" class="repass" name="repass" placeholder="Enter Email" required>
<!-- <input type="hidden" name="token" id="token">-->
<button type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var params = location.href;
var paramsplit = params.split('/');
//console.log(paramsplit);
$("#resetpass").submit(function (e) {
var resetData = {
password: $("#password").val(),
repass: $("#repass").val(),
token: paramsplit[4]
}
console.log(resetData);
// console.log(resetData);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '/reset/:token',
data: JSON.stringify(resetData),
success: function (data) {
//console.log(data); // show response from the php script.
}
});
// e.preventDefault(); // avoid to execute the actual submit of the form.
});
</script>
<style CSS>
@import url("https://bootswatch.com/flatly/bootstrap.min.css");
</style>
</html>
我的mail.route.js是:
app.route('/reset/:token').get(mail.renderresetpage);
app.route('/reset/:token').post(mail.resetpassword);
一切正常。仅在按下提交按钮后不显示成功消息
你的贡献将大有帮助 提交发件人将导航到表单的操作。您可以向按钮添加一个“onclick”,使您保持在同一页面中,并从中发送ajax请求。因此,您可以成功处理ajax。提交发件人将导航到表单的操作。您可以向按钮添加一个“onclick”,使您保持在同一页面中,并从中发送ajax请求。因此,您可以成功地处理ajax
app.route('/reset/:token').get(mail.renderresetpage);
app.route('/reset/:token').post(mail.resetpassword);