账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Ajax访问SpringMVC的Controller进入error
    • 2018-03-08 00:00
    • 11
    29
    0

    Ajax访问SpringMVC的Controller进入error

    ##* JSP
    <form action="#" method="post" id="loginform" onsubmit="return false">
            <input type="text" id="username" name="username" class="name" placeholder="username" required="">
            <input type="password" id="password" name="password" class="password" placeholder="password" required="">
            <span id="msg" style="color:#F00;font-size:14px;"></span><br><br>
            <ul>
                <li>
                    <input type="checkbox" id="brand1" value="">
                    <label for="brand1"><span></span>记得我</label>
                </li>
            </ul>
            <a href="#">忘记密码?
            </a><br>
            <div class="clear"></div>
            <input type="button" id="submit" value="Login" onclick="login()">
        </form>
        
    ##*Ajax
    <script type="text/javascript">
            function login(that) {
                $.ajax({
                    data: "username=" + $("#username").val() + "&password=" + $("#password").val(),
                    type: "post",
                    url: "/checklogin",
                    dataType: "json",
                    error: function (data) {
                        alert("出现异常,请稍后重试");
                        $(that).removeClass("processing");
                    },
                    success: function (response) {
                        $(that).removeClass("processing");
                        if (response == "error") {
                            $("#msg").text("用户名或密码错误");
                        } else {
                            window.location.href = "/welcome";
                        }
                    }
                });
            }
    </script>
    
    ##Controller
    @Controller
    public class LoginController {
        @Autowired
        private UserService userService;
        
        @RequestMapping("/checklogin")
        @ResponseBody
        public String checkLogin(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session){
            User user = userService.login(username, password);
            if(user != null){
                return "success";
            }
            else{
                return "error";
            }
        }
        
    }
    

    error返回(object object)

    刚刚学习虚心请教

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 人间人 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部