使用了jQuery $.Ajax访问springMVC的controller 请求成功 可是回调函数进入了error函数 并且浏览器返回错误信息
Failed to load resource: the server responded with a status of 404 ()
下面放代码
Ajax
function login(that) {
$.ajax({
data: {
username:$("#username").val(),
password:$("#password").val()
},
type: "post",
url: "/checklogin",
dataType: "json",
error: function (data) {
console.log(data);
$(that).removeClass("processing");
},
success: function (response) {
$(that).removeClass("processing");
if (response == "error") {
$("#msg").text("用户名或密码错误");
} else {
window.location.href = "/welcome";
}
}
});
}
Controller
@Controller
public class LoginController {
@Autowired
private UserService userService;
@RequestMapping("/checklogin")
public String checkLogin(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session){
System.out.println(username + "-" + password);
User user = userService.login(username, password);
if(user != null){
return "success";
}
else{
return "error";
}
}
}
慕尼黑8549860
相关分类