我有一个简单的用户登录面板,当用户名密码不正确弹出时会显示一条消息。但问题是,通常(并非总是)对于不正确或空字段,弹出窗口会出现两次。我知道它可以有简单的解决方案,但我已经尝试了很长时间来解决它。所以。任何有效的建议都会有很大的帮助。
我的javascript代码如下所示:
$("#password").keypress(function(e)
{
if (e.which == 13)
{
performLogin();
}
});
function performLogin(){
var uName = $("#userName").val();
var uPass = $("#password").val();
var licenseType = $("#licenseType").val();
$.post('./qServer',{
type:'login',
userName:uName,
password:uPass,
licenseType:licenseType
}, function(data){
someText = data.replace(/(\r\n|\n|\r)/gm,"");
if(someText=='1'){
window.location.reload();
}
else if(someText=='2')
{
$.prompt("Enter Required Field(s) Value");
}
else if(someText=='0')
{
$.prompt("Database Err: User Name or Password not valid");
}
else if(someText=='3')
{
$.prompt("Database Err: Invalid user");
}
else if(someText=='-1')
{
$.prompt("Failed to connect with Database");
}
else if(someText=='-2')
{
$.prompt("Syntem is unavailable please wait..");
}
else if(someText=='-3')
{
$.prompt("System is ready to undeployment. If you want to resume services without further deployment please restart you server");
}
else if(someText=='52e')
{
$.prompt("Active Directory Err: invalid credentials");
}
else if(someText=='525')
{
$.prompt("Active Directory Err: user not found");
}
else if(someText=='530')
{
$.prompt("Active Directory Err: not permitted to logon at this time");
}
else if(someText=='531')
{
$.prompt("Active Directory Err: not permitted to logon at this workstation");
}
else if(someText=='532')
{
$.prompt("Active Directory Err: password expired (remember to check the user set in osuser.xml also)");
}
else if(someText=='533')
{
$.prompt("Active Directory Err: account disabled");
}
else if(someText=='701')
{
$.prompt("Active Directory Err: account expired");
}
else if(someText=='773')
{
$.prompt("Active Directory Err: user must reset password");
}
else if(someText=='775')
{
$.prompt("Active Directory Err: user account locked");
}
else
{
$.prompt("Active Directory Err: not authenticated user!");
}
});
}
注意 我已检查并发现在给出密码后按Enter键时,问题就出现了。
答案 0 :(得分:0)
好吧,我自己可以解决问题,只需添加一行如下:
$("#password").keypress(function(e)
{
if (e.which == 13)
{
e.stopImmediatePropagation();
performLogin();
}
});
e.stopImmediatePropagation()
停止多次点击performLogin()
。