AJax请求后台,后台有记录,前端success回掉不进入解决方案

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>
发布了84 篇原创文章 · 获赞 77 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/lujiachun1/article/details/86690092
今日推荐