关闭模态后如何刷新下面的页面?

时间:2011-08-15 09:09:22

标签: jquery ajax

我的应用程序是这样的,用户填写表单,如果他没有登录或注册,单击提交按钮后,会出现一个包含注册字段的jquery模式框,用户填写模态字段后单击注册按钮,此模式关闭并插入新成员的注册详细信息。

现在的问题是,如何刷新同一页面,在模态关闭后,使页面显示当前用户是注册会员?,我只是想知道如何刷新下面的页面,

这就是我现在拥有的东西

 if(userid == ""){
        $( "#dialog:ui-dialog" ).dialog( "destroy" );

        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height: 230,
        width: 350,
            modal: true,
            buttons: {
                "Register": function(){
                    $(this).dialog("close");
                $('div#registerpopup').dialog({
                   resizable: false,
                   height: 485,
                   width: 420,
                   modal: true,
                   buttons: {
                        "Register": function(){
                            var username = $('#username').val();
                            var password = $('#password').val();
                            var retypepassword = $('#retypepassword').val();
                            var emailaddress = $('#emailaddress').val();
                            var secondaryemailaddress = $('#secondaryemailaddress').val();
                            var secretquestion = $('#secretquestion').val();
                            var secretanswer = $('#secretanswer').val();
                            var reffcode = $('#reffcode').val();
                            var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
                          if(username == "" || username.length < 1 || username.length > 30 || username.indexOf(' ') != -1){
                            alert("Username is required\n-should not be less than 1 character\n-should not be more than 30 characters\n-It may also not contain spaces");
                            return false;
                          }
                          if(password.length < 7 || password.indexOf(' ') !=  -1 ){
                            alert("Password should not be empty\n-should at least be 7 characters");
                            return false;
                          }
                          if(retypepassword != password){
                            alert("re-type password should be the same as the password!");
                            return false;
                          }
                          if(emailaddress == "" || emailaddress.search(emailRegEx) == -1){
                            alert("Email Address is required and should be a valid email address");
                            return false;
                          }
                          if(secondaryemailaddress == "" || secondaryemailaddress.search(emailRegEx) == -1){
                            alert("Secondary Email address should be the same as the primary email address!");
                            return false;
                          }
                          if(secretquestion == ""){
                            alert("Secret Question is required!");
                            return false;
                          }
                          if(secretanswer == ""){
                            alert("Secret Answer is required!");
                            return false;
                          }
                          if(reffcode == ""){
                            alert("Reference Code is required!");
                            return false;
                          }
                          else {
                            $.ajax({
                               type: "POST",
                               url: "classes/ajax.registerpopup.php",
                               timeout: 8000,
                               data: "username="+username+"&password="+password+"&emailaddress="+emailaddress+
                                     "&secondaryemailaddress="+secondaryemailaddress+"&secretquestion="+secretquestion+
                                     "&secretanswer="+secretanswer+"&reffcode="+reffcode,
                               success: function(){
                                 alert("You are now registered!");
                               }
                            });
                          }
                          $(this).dialog("close");
                        }
                   }
                });
                },
                "Log in": function() {
                    $(this).dialog("close");
                $('div#loginpopup').dialog({
                  resizable: false,
                  height: 230,
                  width: 350,
                  modal: true
                })
                }
            }
        });
    return false;
 }

2 个答案:

答案 0 :(得分:1)

如果您想刷新整页,请不要致电

window.location = 'pathToCurrentPage'
模态结束后

?这会强制页面刷新。

从用户体验的角度来看,更新显示用户已登录的页面部分可能会更好

答案 1 :(得分:0)

在弹出窗口的关闭事件中调用此函数:

document.parent.location.reload();