81,092
社区成员
发帖
与我相关
我的任务
分享
success: function(data)
试试
UserService service = new UserService();
JsonObject object = new JsonObject();
if (name != null && password != null){
boolean flag = service.login(name,password);
if (flag){
session.setAttribute("user",name);
//使用json发送数据,status中1代表成功,0代表失败
object.addProperty("status",1);
object.addProperty("message","登录成功");
object.addProperty("address",request.getContextPath()+ "/index.jsp");
out.write(object.toString());
}else{
object.addProperty("status",0);
object.addProperty("message","用户名或者密码错误");
out.write(object.toString());
}
}
ajax部分:
$.ajax({
type: "POST",
url: "login",
dataType: "json",
data: {name: $("#username").val(), password: $("#password").val()},
success: function (data) {
if (data.status == 1) {
$(location).attr("href", data.address);
} else if (data.status == 0) {
$("#message").show().html(data.message);
}
}
});
success: function(data){
debugger;
}
如上图 在success方法里面加入一个debugger,然后在浏览器按F12 运行起来 如果没有debug 说明没有进入success方法 进入了error方法 如果有debug 那么就进入了success 这个时候你看你的代码是怎么走找出错误