问剑白玉京 2021-12-02 09:52 采纳率: 74.2%
浏览 40
已结题

为什么ajax 登录之后,页面刷新一次,必须后退一个页面才能显示提示信息

先看问题

img

img

img

代码
ajax

$.ajax({
                type: "POST",
                url: "/sswz/user/goregister",
                dataType: "html",
                async: false,
                data: {
                    identity: identity,
                    account: account,
                    password: password,
                    Confirmpassword: Confirmpassword,
                    realname: realname,
                    telephone: telephone
                },
                success: function (result) {
                     if (result === "accountnull") {
                        layer.open({
                            type: 1
                            , offset: 'auto'
                            , content: '<div style="padding: 20px 100px;">' + '账户不能为空' + '</div>'
                            , btn: '确定'
                            , btnAlign: 'c' //按钮居中
                            , skin: 'demo-class'
                            , shade: 0 //不显示遮罩
                            , icon: 7
                            , yes: function () {
                                layer.closeAll();
                            }
                        });
                    } else if (result === "passwordnull") {
                        layer.alert('密码不能为空',{icon:7});
                    } else if (result === "namenull") {
                        layer.alert('真实姓名不能为空',{icon:7});
                    } else if (result === "telnull") {
                        layer.alert('电话不能为空',{icon:7});
                    } else if (result === "notequal") {
                        layer.alert('两次密码不一致',{icon:2});
                    } else if (result === "success") {
                         layer.open({
                             type: 1
                             , offset: 'auto'
                             , content: '<div style="padding: 20px 100px;">' + '注册成功!' + '</div>'
                             , btn: '确定'
                             , btnAlign: 'c' //按钮居中
                             , skin: 'demo-class'
                             , shade: 0 //不显示遮罩
                             , icon: 7
                             , yes: function () {
                                 window.location.href = "/sswz/index.html";
                                 layer.closeAll();
                             }
                         });
                     }
                }
            });

java

@GetMapping("/user/register")
    public String toregister()
    {
        return "register";
    }

    @PostMapping("/user/goregister")
    @ResponseBody
    public String register(String identity, String account, String password, String Confirmpassword,
                           String realname, String telephone) {


        if (account == null || "".equals(account)) {
            return "accountnull";
        } else if ("".equals(password) || "".equals(Confirmpassword)) {
            return "passwordnull";
        } else if ("".equals(realname)) {
            return "namenull";
        } else if ("".equals(telephone)) {
            return "telnull";
        } else if (!password.equals(Confirmpassword) ) {
            return "notequal";
        } else {

            System.out.println(1);
            return "success";
        }
    }

  • 写回答

1条回答 默认 最新

  • bdmh 优质创作者: 移动开发技术领域 2021-12-02 09:57
    关注

    应该是window.location.href的问题,这个已经发生页面变化了

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月2日
  • 创建了问题 12月2日