使用了jQuery $.Ajax访问springMVC的controller 请求成功 可是回调函数进入了error函数 并且浏览器返回错误信息Failed to load resource: the server responded with a status of 404 ()下面放代码Ajaxfunction 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@Controllerpublic 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"; } }}
3 回答
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
添加回答
举报
0/150
提交
取消