Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reload a jQuery dialog box from within the dialog?

I load a page within a jQuery Dialog. After an ajax command is completed, I would like to be able to reload the same page within the jQuery Dialog. How can I reload a jQuery Dialog from within the page that is loaded in the Dialog?

Parent Page (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>

Dialog contents page (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>
like image 749
Rob Avatar asked Dec 04 '22 16:12

Rob


1 Answers

You are loading content from another page into the dialog container in the current page, so there is really only one page in play here. I would recommend only loading partial html (no <head> or <body> tags) from your dialog source page.

So you can either destroy the dialog and recreate it to reload the dialog content:

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 });
}

Or, you can reload the entire page.

window.location.reload();
like image 153
jrummell Avatar answered Dec 07 '22 05:12

jrummell