微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

忘记密码不会使用 Pug 路由到 api

如何解决忘记密码不会使用 Pug 路由到 api

我正在尝试使用 nodejs、express 和模板引擎 PUG 重置密码,但由于某种原因,当我输入电子邮件 ID 后单击提交时,没有任何反应。

下面是位于 root/views/users 中的 Forget-password.pug

block content
  div.container
    div.row
      div.col
        h1 Forgot password
        p Enter your email address below. If we have it on file,we will send you a reset email.
        div.forgot-message.alert.alert-success(style="display:none;") Email address received. If you have an email on file we will send you a reset email. Please wait a few minutes and check your spam folder if you don't see it.
        form#forgotPasswordForm.form-inline(onsubmit="return false;")
          div.form-group
            label.sr-only(for="email") Email address:
            input.form-control.mr-2#emailFp(type='email',name='email',placeholder="Email address")
          div.form-group.mt-1.text-center
            button#fpButton.btn.btn-success.mb-2(type='submit') Send email
 
  script.
    $('#fpButton').on('click',function() {
      $.post('/api/users/getUsers',{
        email: $('#emailFp').val(),},function(resp) {
        $('.forgot-message').show();
        $('#forgotPasswordForm').remove();
      });
    });

user.router 位于 /root/users/user.router.js

const router = express.Router();

router.post("/forgetpassword",forgetpassword); //api to handle forget password and send email

router.get('/x/forget-password',function(req,res,next) { 
  res.render('users/forget-password',{ });
});
module.exports = router;

我正在使用 url (http://localhost:1111/api/users/x/forget-password) 访问忘记密码页面,但是在输入电子邮件并单击提交后,没有任何反应,似乎没有能够调用post api /forgetpassword

解决方法

使用相应的路由 /forgetPassword 并将您的 js 事件包装在 jQuery .ready() 处理程序中:

script.
    $(function () {
        $('#fpButton').on('click',function () {
            $.post('/forgetPassword',{
                email: $('#emailFp').val(),},function (resp) {
                $('.forgot-message').show();
                $('#forgotPasswordForm').remove();
            });
        });
    });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。