问剑白玉京 2021-12-02 09:52 采纳率: 76.9%
浏览 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日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器