AJax请求后台,后台有记录,前端success回掉不进入解决方案
在Controller方法上添加ResponseBody标签即可
@RequestMapping("listClient")
@ResponseBody
public ModelAndView listClient() {
ModelAndView mav = new ModelAndView();
List<Client> clientList = clientService.list();
mav.addObject("clientList", clientList);
mav.setViewName("beian");
return mav;
}
ajax部分
<script type="text/javascript">
function login() {
$.ajax({
type: "POST", // 方法类型
url: "getUser", // url
cache: false,
async : false, // 同步:意思是当有返回值以后才会进行后面的js程序
data: $('#loginForm').serialize(), // 请求参数
dataType: "json",
success: function (result) {
console.log(result.username); // 调试用
if (result != undefined) {
alert("登录成功!");
window.location.href = 'wastesPlatform.html';
console.log("页面跳转");
} else {
alert("账号或密码错误,请重试!");
}
},
error:function (result) {
alert("账号或密码错误,请重试!");
}
});
}
</script>