function login()
{
var userName = document.getElementById("loginName").value;//通过ID获取元素
var pwd = document.getElementById("loginPwd").value;
var checkUrl = "<%= _basePath%>/checkLogin";//struts2中的action的name
var data = $.ajax({
url:checkUrl,
data:{userName:userName,password:pwd},//其中前标的userName对应的是checkUrl="<%= _basePath%>/checkLogin"中的checkLogin对应的Struts.xml中的action中的class中的参数名。而后一个userName为本函数定义的值。
async:false,//async为异步传输。false则为同步传输。
alert("用户名与密码不匹配");
return;
}
//alert("ok") //用户密码匹配后进行页面跳转
form1.action = "<%= _basePath%>/login";
form1.submit();//当前页面提交
}
{
var userName = document.getElementById("loginName").value;//通过ID获取元素
var pwd = document.getElementById("loginPwd").value;
var checkUrl = "<%= _basePath%>/checkLogin";//struts2中的action的name
var data = $.ajax({
url:checkUrl,
data:{userName:userName,password:pwd},//其中前标的userName对应的是checkUrl="<%= _basePath%>/checkLogin"中的checkLogin对应的Struts.xml中的action中的class中的参数名。而后一个userName为本函数定义的值。
async:false,//async为异步传输。false则为同步传输。
})
//执行action中的class的method方法,在method方法中调用了service方法,在service方法中调用了Dao方法,之后返回结果。得到dataresponseText。
alert("用户名与密码不匹配");
return;
}
//alert("ok") //用户密码匹配后进行页面跳转
form1.action = "<%= _basePath%>/login";
form1.submit();//当前页面提交
}