Code:
/ / send an asynchronous request for registration
$.ajax({
type:"post",
url :"/user/register",
data:$("form").serialize(),
dataType:"json",
success:function(data){
alert(data);
if(data == "success"){
alert("");
window.location.href="/";//
}else if(data == "fail"){
alert(":"+data);
}
},
error:function(data){
alert("error:"+data);
if(data == "error")
alert(""+data);
window.location.href="/";
}
});
@ RequestMapping (value = "/ user/register", method = RequestMethod.POST)
public ModelMap register(User user){
ModelMap map = new ModelMap();
try {
System.err.print(user.toString());
int result = userService.register(user);
if (result > 0) {
//
map.put("res","success");
}else {
map.put("res","fail");
}
return map;
}catch (Exception e){
e.printStackTrace();
map.put("data","error");
return map;
}
}
and window.location.href= "/"; this line of code is not executed because it does not jump
the database inserts data and does not throw an exception, so why error?