jQuery: Load Modal Dialog Contents via Ajax

前端 未结 6 1995
天涯浪人
天涯浪人 2020-11-27 03:27

Currently my Modal Dialog is like this


 
  

        
相关标签:
6条回答
  • 2020-11-27 03:40

    Check out this blog post from Nemikor, which should do what you want.

    http://blog.nemikor.com/2009/04/18/loading-a-page-into-a-dialog/

    Basically, before calling 'open', you 'load' the content from the other page first.

    jQuery('#dialog').load('path to my page').dialog('open'); 
    
    0 讨论(0)
  • 2020-11-27 03:43
    $(function ()    {
        $('<div>').dialog({
            modal: true,
            open: function ()
            {
                $(this).load('Sample.htm');
            },         
            height: 400,
            width: 400,
            title: 'Dynamically Loaded Page'
        });
    });
    

    http://www.devcurry.com/2010/06/load-page-dynamically-inside-jquery-ui.html

    0 讨论(0)
  • 2020-11-27 03:44

    try to use this one.

    $(document).ready(function(){
    $.ajax({
        url: "yourPageWhereToLoadData.php",
        success: function(data){
            $("#dialog").html(data);
        }   
    });
    
    $("#dialog").dialog(
           {
            bgiframe: true,
            autoOpen: false,
            height: 100,
            modal: true
           }
    );
    });
    
    0 讨论(0)
  • 2020-11-27 03:46

    may be this code may give you some idea.

    http://blog.nemikor.com/2009/04/18/loading-a-page-into-a-dialog/

    $(document).ready(function() {
        $('#page-help').each(function() {
            var $link = $(this);
            var $dialog = $('<div></div>')
                .load($link.attr('href'))
                .dialog({
                    autoOpen: false,
                    title: $link.attr('title'),
                    width: 500,
                    height: 300
                });
    
            $link.click(function() {
                $dialog.dialog('open');
    
                return false;
            });
        });
    });
    
    0 讨论(0)
  • 2020-11-27 03:54
    var dialogName = '#dialog_XYZ';
    $.ajax({
            url: "/ajax_pages/my_page.ext",
            data: {....},
            success: function(data) {
              $(dialogName ).remove();
    
              $('BODY').append(data);
    
              $(dialogName )
                .dialog(options.dialogOptions);
            }
    });
    

    The Ajax-Request load the Dialog, add them to the Body of the current page and open the Dialog.

    If you only whant to load the content you can do:

    var dialogName = '#dialog_XYZ';
    $.ajax({
                url: "/ajax_pages/my_page.ext",
                data: {....},
                success: function(data) {
                  $(dialogName).append(data);
    
                  $(dialogName )
                    .dialog(options.dialogOptions);
                }
    });
    
    0 讨论(0)
  • 2020-11-27 03:56
    <button class="btn" onClick="openDialog('New Type','Sample.html')">Middle</button>
    
    <script type="text/javascript">
        function openDialog(title,url) {
            $('.opened-dialogs').dialog("close");
    
            $('<div class="opened-dialogs">').html('loading...').dialog({
                position:  ['center',20],
                open: function () {
                    $(this).load(url);
    
                },
                close: function(event, ui) {
                        $(this).remove();
                },
    
                title: title,
                minWidth: 600            
            });
    
            return false;
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题