Problems refreshing pages when logging in and submitting membership

Asked 2 years ago, Updated 2 years ago, 70 views

Hello, I'm developing a website with node.js, and I want to develop a login and membership page.

For input, the verification logic was implemented using the validation of jquery.

And when you enter all the input information, press the submit button, and if the db is read and the account information is wrong,

The page is refreshed by throwing a failure message. When it is refreshed, the information entered in the input is reset.

How can I solve the above problem?

Below is the code I'm implementing.

Clicking the login button

$.ajax({
          type: "POST",
          url: "/login",
          dataType: "json",
          data: $("form").serialize(), // when forwarding data to the server
          success: call success callback when function(response) { // successful
            if(response == 'success') {

            } } else {
            $("#message").html("<p style='color:red'> ID or password is invalid.</p>");
            }
         }
   });
   return false;

Process db, etc. after requesting post

router.post('/login', function(req, res, next) {

  pool.getConnection(function(err, conn) {

    // DB Account Existence
    var selectQuery = 'SELECT * FROM user WHERE email = ' + mysql.escape(req.body.email);
    conn.query(selectQuery, function(err, rows) {
      next();
    });
  })
  }, }, passport.authenticate('local-login', {
      successRedirect : '/',
      failureRedirect : '/login',
      failureFlash : true
  })
);

I appreciate your help.

Thank you.

ajax node.js

2022-09-22 21:30

1 Answers

I think there is no problem with the code, so could you show me the HTML with the form tag?

If you put it in onsubmit in the form tag, there seems to be no problem.

Or just put return false; under the if or else code.


2022-09-22 21:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.