【问题标题】:Refresh window when username and password mismatch用户名和密码不匹配时刷新窗口
【发布时间】:2013-10-26 14:39:55
【问题描述】:

我正在使用 node.js 构建一个应用程序。我制作了一个登录表单,它工作正常,但如果用户输入了错误的用户名和密码,那么他必须刷新窗口,然后输入正确的用户名和密码才能继续下一个屏幕。

如何让用户在登录窗口后进入而不刷新?

逐步解释上述问题:

  1. 用户输入用户名和密码(如果两者都正确)。

  2. 用户已登录。

但是:

  1. 用户输入用户名和密码(如果其中一个错误)。

  2. 刷新窗口。

  3. 用户输入正确的用户名和密码。

  4. 用户已登录。

如何避免“刷新窗口”步骤?如果不清楚,我可以解释更多。

【问题讨论】:

    标签: node.js


    【解决方案1】:

    我已经编辑了答案,你可以这样做。

    socket.on('login_check', function(email, pwd) { 
        connection.query("SELECT id,user_type FROM user WHERE email = '"+email+"' AND password = '"+pwd+"'ORDER BY name ", 
        function (error, results, fields) { 
            if (error) { 
                console.log(error);  
            } 
            if (results[0]) { 
                // some code     
            } else { 
                response.writeHead(200, {
                    'Location': '/login-path'
                    // add other headers here...
                    // you may also show the email in the text box
                    // again by passing the variable email to the template
                    // engine you are using or how ever you are doing it
                });
        response.end(); 
            } 
        }); 
    });
    

    【讨论】:

    • 您能进一步帮助我吗?我的代码是 - socket.on('login_check', function(email, pwd){ connection.query("SELECT id,user_type FROM user WHERE email = '"+email+"' AND password = '"+pwd+"'ORDER BY name ", function (error, results, fields) { if (error) { console.log(error); } if (results[0]) { // some code } else { // 如何在这里使用你的代码? } }); });如何在这里得到回应??
    猜你喜欢
    • 2021-04-10
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多