jQuery 使用对话框完成 AJAX 调用后如何重新加载页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15962223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:06:49  来源:igfitidea点击:

How do I reload the page after an AJAX call is done with a dialog?

ajaxjqueryjquery-ui-dialogjquery-dialog

提问by Mike

so I have a dialog UI with a form once a user click on a link it opens. Once they click "Add button" it create a AJAX call that submits the data into the database. What I need to add is reload() function to refresh the page.

因此,一旦用户单击它打开的链接,我就会有一个带有表单的对话框 UI。一旦他们单击“添加按钮”,它就会创建一个 AJAX 调用,将数据提交到数据库中。我需要添加的是 reload() 函数来刷新页面。

How can I add the reload function?

如何添加重新加载功能?

I have tried to add windows.localtion.reload(); you can see it my code. That line does not work for some reason

我试图添加 windows.localtion.reload(); 你可以看到我的代码。那条线由于某种原因不起作用

//Update contact dialog box
    $( "#contact-edit" ).dialog({
    resizable: false,
    width: 500,
    modal: true,
    autoOpen: false,
    buttons: {
        "Update Info": function(e) {

        var formData = $('#edit-form').serialize();

        //submit record
        $.ajax({    
            type: 'POST',
            url: 'ajax/handler-contact-update.php',     
            data: formData,
            dataType: 'json',
            cache: false,
            timeout: 7000,
            success: function(data) {           

                $('#response-edit').removeClass().addClass((data.error === true) ? 'errorBox' : 'passBox').html(data.msg).fadeIn('fast');   

                if ($('#response-edit').hasClass('passBox')) {
                    $('#response-edit').fadeIn('fast');
                    $('#edit-form').hide();
                        $( "#contact-edit" ).dialog("close");
                        windows.localtion.reload();
                }       
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {

                $('#response-edit').removeClass().addClass('errorBox')
                            .html('<p>There was an<strong> ' + errorThrown +
                                  '</strong> error due to a<strong> ' + textStatus +
                                  '</strong> condition.</p>').fadeIn('fast');           
            },              
            complete: function(XMLHttpRequest, status) {            
                    $('form')[0].reset();
                    //$( this ).dialog( "close" );


            }
        }); 



        },
        Cancel: function() {
            $( this ).dialog( "close" );
        },
        Submit: function(){
            $('form')[0].submit();
        }
    }
});

回答by 99823

You have a typo:

你有一个错字:

windows.localtion.reload();

Should be

应该

window.location.reload();

回答by Manjuboyz

You can try many ways to reload the page, I have tried few, at least few may help somebody.

您可以尝试多种方法来重新加载页面,我尝试过的很少,至少很少有人可以帮助某人。

location.reload()

location.reload(false)

window.location = window.location

window.location.reload();

If you using link then use this :

如果您使用链接然后使用这个:

location.href = location.href