无法登录总是失败 [英] Cant Login always failed

查看:81
本文介绍了无法登录总是失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好日子我是webdev的新手。我试图创建一个项目,其中有一个登录表单,用户将输入他们的用户名和密码。只要按钮被点击它将显示一个消息登录成功,如果用户名和密码没有存储在xml它将显示登录失败!!有人可以告诉我代码的错误是什么?登录保持提示消息登录失败当按钮为click.Below是代码。提前提供帮助。



这里是user.xml代码



user.xml

 <用户> 
< user>
< username> A< / username>
< password> 12345< / password>
< / user>
< / users>

尊重login.html代码

 <!DOCTYPE HTML> 
< html lang =en-US>
< head>
< / head>
< body>
< form id =frmloginname =frmloginmethod =postaction =Loginonsumbit =return false;>
< p> ENTER USER NAME< input type =textname =login_usernameid =username>< / p>
< p> ENTER PASSWORD< input type =passwordname =login_passid =password>< br>< br>
< input type =buttonclass =buttonvalue =登录onclick =login()>
< / p>

< / form>
< script>
window.login = function(e)
{

if(document.frmlogin.login_username.value ==)
{
alert 用户名不为空);
返回;
}
else if(document.frmlogin.login_pass.value ==)
{
alert(Password is not blank);
返回;
}

else
{
var xmlDoc;
if(window.XMLHttpRequest){
xhttp = new XMLHttpRequest();
} else {// IE 5/6
xhttp = new ActiveXObject(Microsoft.XMLHTTP);
}

xhttp.overrideMimeType('text / xml');

xhttp.open(GET,user.xml,false);
xhttp.send(null);
xmlDoc = xhttp.responseXML;

var ktra = true;
var xml = xmlDoc.childNodes [0] .childNodes [1];

var name = xml.childNodes [username];
var pass = xml.childNodes [password];
(var i = 0; i< xml.childNodes.length; i ++){
if(xml.childNodes [i] .nodeName =username)
name = xml.childNodes [一世];
if(xml.childNodes [i] .nodeName =password)
pass = xml.childNodes [i];
}
if(name.textContent == frmlogin.login_username.value&& pass.textContent == frmlogin.login_pass.value)
{
ktra = true;

}
else
{
ktra = false;
}

if(ktra == true)
{
alert(登录成功!!!);
}
else
{
alert(登录失败!!!);
}
}
}
< / script>
< / body>
< / html>


解决方案

您正在将字符串与=进行比较。尝试使用 xml.childNodes [i] .nodeName ==username和密码相同。也不要用不同于英语的其他语言来命名变量。很难读


Good day I am a newbie in webdev. Im trying to create a project where in there is a login form that users will input their username and password.Whenever the button is click it will display a message Login successfully and if the username and password is not stored in the xml it will display Login Failed!!.Can someone tell me what is the mistake of the code?Login keeps having alert message Login Failed when button is click.Below is the code.Thanks in advance for help.

here is the user.xml code

user.xml

<users>
    <user>
        <username>A</username>
        <password>12345</password>
    </user>
</users>

heres the login.html code

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
    </head>
    <body>
        <form id="frmlogin" name="frmlogin" method="post" action="Login" onsumbit="return false;">
            <p>ENTER USER NAME <input type="text" name="login_username" id="username"></p>
            <p> ENTER PASSWORD <input type="password" name="login_pass" id="password"><br><br>
                <input type="button" class="button" value="Log in" onclick="login()">
            </p>

        </form>
        <script>            
            window.login = function(e)
            {

                if (document.frmlogin.login_username.value == "") 
                {
                    alert("User name is not blank");
                    return;
                }
                else if(document.frmlogin.login_pass.value == "")
                {
                    alert("Password is not blank");
                    return;
                }

                else
                {
                    var xmlDoc;
                    if (window.XMLHttpRequest) {
                        xhttp = new XMLHttpRequest();
                    } else {    // IE 5/6
                        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }

                    xhttp.overrideMimeType('text/xml');

                    xhttp.open("GET", "user.xml", false);
                    xhttp.send(null);
                    xmlDoc = xhttp.responseXML;

                    var ktra=true;
                    var xml=xmlDoc.childNodes[0].childNodes[1];

                    var name = xml.childNodes["username"];        
                    var pass=xml.childNodes["password"];
                    for(var i=0;i<xml.childNodes.length;i++){
                        if(xml.childNodes[i].nodeName="username")
                            name = xml.childNodes[i];
                        if(xml.childNodes[i].nodeName="password")
                            pass = xml.childNodes[i];
                    }
                    if(name.textContent==frmlogin.login_username.value &&pass.textContent==frmlogin.login_pass.value)
                    {
                        ktra=true;        

                    }
                    else
                    {
                        ktra=false;
                    }

                    if(ktra==true)
                    {
                        alert("Login Successfully !!!");
                    }
                    else
                    {
                        alert("Login Failed !!!");
                    }
                }
            }
        </script>
    </body>
</html>

解决方案

You are comparing strings with "=". Try with xml.childNodes[i].nodeName=="username" and the same for the password if. Also do not name variables in other languages different than English. Its hard to read.

这篇关于无法登录总是失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆