HTML
<form action="index.html" onsubmit="return(login())">
UserName:<input type="text" name="uname" id="username"><br>
Password:<input type="password" name="pass" id="password"><br>
<input type="submit" value="Login">
</form>
的JavaScript
function login() {
var invocationData = {
adapter : 'sq',
procedure : "validateLogin",
parameters : [$('#username').val(),$('#password').val()]
};
var options = {
onSuccess : success,
onFailure : failure
};
WL.Client.invokeProcedure(invocationData, options);
}
function success() {
var allNames = new String();
var allpass = new String();
for (var i = 0; i < response.invocationResult.resultSet.length; i++) {
allNames+= response.invocationResult.resultSet[i].name;
allpass+= response.invocationResult.resultSet[i].pass;
}
var a=new String();
var b=new String();
a=JSON.stringify(allNames);
b=JSON.stringify(allpass);
if (a==$('#username').val() && b==$('#password').val() ){
return true;
} else {
return false;
}
}
function failure() {
return false;
}
适配器程序
var query = WL.Server.createSQLStatement(
"select name,pass from userreg where name=? and pass=?");
function validateLogin(username,password) {
return WL.Server.invokeSQLStatement({
preparedStatement : query,
parameters : [username,password]
});
}
答案 0 :(得分:1)
<强> HTML:强>
<form id="frmId" onsubmit="return(login())">
UserName:<input type="text" name="uname" id="username"><br>
Password:<input type="password" name="pass" id="password"><br>
<input type="submit" value="Login">
</form>
成功功能:
function success() {
var allNames = new String();
var allpass = new String();
for (var i = 0; i < response.invocationResult.resultSet.length; i++) {
allNames+= response.invocationResult.resultSet[i].name;
allpass+= response.invocationResult.resultSet[i].pass;
}
var a=new String();
var b=new String();
a=JSON.stringify(allNames);
b=JSON.stringify(allpass);
if (a==$('#username').val() && b==$('#password').val() ){
$("#frmId").attr('action', URL of the page you wants to redirect to);
return true;
} else {
return false;
}
}