public void login() {
String pwd = getPara("pwd");
String name = getPara("name");
String sql = "select * from userinfo where DisplayName = ? limit 1";
Userinfo userinfo = Userinfo.dao.findFirst(sql, name);
if (userinfo != null) {
if (userinfo.getUserPwd().equals(pwd)) {
String sessionId = SessionIdKit.me().generate(getRequest());
setSessionAttr(sessionId, userinfo);
setCookie("user", sessionId, 60000);
setAttr("state", 1);
setAttr("msg", "登录成功!");
renderJson();
} else {
setAttr("state", 0);
setAttr("msg", "登录失败!");
renderJson();
}
} else {
setAttr("state", 0);
setAttr("msg", "登录失败!");
renderJson();
}
}接口是这样写的
$.ajax({
data : data.field,
url : "/JFinalTest/login",
type : "post",
success : function(data) {
if (data.state == 1) {
window.location.href ="/JFinalTest/index.html";
} else {
layer.msg("用户名或者密码错误!", {
time : 5000,
icon : 5
}, function(index) {
layer.close(index);
});
}
return false;
},
error : function(data) {
console.log("网络请求失败");
return false;
layer.msg('网络请求失败,请重试!', {
time : 3000,
icon : 5
}, function(index) {
layer.close(index);
});
}
});这个是ajax的提交
Controller : cn.pangpython.controller.IndexController.(IndexController.java:1)
Method : login
Parameter : name=fandy pwd=fandy
第一次点击提交 接口是访问了的 但是进了 ajax的error函数 再次点击提交就正常了 有没有大神解答一下