编程语言
首页 > 编程语言> > javascript – 如何从对话框中重新加载jQuery对话框?

javascript – 如何从对话框中重新加载jQuery对话框?

作者:互联网

我在jQuery对话框中加载了一个页面.完成ajax命令后,我希望能够在jQuery对话框中重新加载相同的页面.如何从Dialog中加载的页面中重新加载jQuery对话框?

父页面(Blah.aspx):

<script type="text/javascript">
    function view_dialog() {
        $('#dialog').load('blah2.aspx').dialog({
            title: 'test' ,
            modal: 'true',
            width: '80%',
            height: '740',
            position: 'center',
            show: 'scale',
            hide: 'scale',
            cache: false });
    }
</script>

<asp:Content
    ID="Content2"
    ContentPlaceHolderID="ContentPlaceHolder1"
    runat="server">

    <input id="Button1" onclick="view_dialog()" type="button" value="button" />
    <div id="dialog" style="display: none"></div>

</asp:Content>

对话框内容页面(blah2.aspx):

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    $(document).ready(function() {
        function doit() {
            var request = $.ajax({
                url: "someurl",
                dataType: "JSON",
                data: {
                    a: 'somevalue'
                }
            });

            request.done(function () {
            //refresh the current dialog by calling blah2.aspx again
        });
    }       
</script>

<asp:Content
    ID="Content2"
    ContentPlaceHolderID="ContentPlaceHolder1"
    runat="server">

    <input id="Button1" onclick="doit()" type="button" value="button" />

</asp:Content>

解决方法:

您正在将其他页面中的内容加载到当前页面中的对话框容器中,因此这里只有一个页面可供使用.我建议只从对话框源页面加载部分html(没有< head>或< body>标记).

因此,您可以销毁对话框并重新创建它以重新加载对话框内容:

function reload_dialog()
{
    $('#dialog').dialog('destroy');
    view_dialog();
}

function view_dialog() {
    $('#dialog').load('blah2.aspx').dialog({
        title: 'test' ,
        modal: 'true',
        width: '80%',
        height: '740',
        position: 'center',
        show: 'scale',
        hide: 'scale',
        cache: false });
}

或者,您可以重新加载整个页面.

window.location.reload();

标签:jquery,javascript,jquery-ui,jquery-dialog
来源: https://codeday.me/bug/20190714/1461702.html