调用jquery-dialog()中的函数


call a function within jquery dialog()

我正在使用jquery dialog(),所以会出现一个弹出窗口。我想调用一个php函数来在弹出窗口中显示信息。我的代码是

 $(document).ready(function() {
                $( "#dialog-form" )
                    .dialog({
                        autoOpen: false,
                        title: "Add Images",
                        //buttons: {"Cancel": function() { $(this).dialog("close"); }},
                        draggable: false,
                        resizable: false 
                });
                $("#addImage").click(function() {
                    $( "#dialog-form" ).dialog("open");
                    return false;
                });
                });
    <button id="addImage">Add Image</button>
        <div id="dialog-form"> <?php function show_php(); ?>
        </div>

然后我有以下功能:函数显示_php(echo"我需要把php代码放在这里");如何调用函数show_php();使用jquery dialog();这可能吗;?

$('#addImage').click(function() {
    $('#dialog-form').load('show.php').dialog({
        autoOpen : false,
        title    : 'dialog title',
        width    : 400,
        position : ['center', 'middle'],
        modal    : true,
        resizable: false,
        buttons: {
            'OK' : function() {
                $(this).dialog("close");
            }
        }
    }).dialog('open');
    return false;
});
show.php
<?php
    echo "this is show.php";
?>
or
$('<div />').load('show.php').dialog({ 
    ......
});

使用查询对话框的open事件触发ajax调用并填充它。

$( "#dialog-form" ).dialog({
   open: function(event, ui) {
     // Here you make an ajax call to load the content of the dialog from the server
   }
});
you can use ajax by modifying your current file like this 

 $(document).ready(function() {
                    $( "#dialog-form" )
                        .dialog({
                            autoOpen: false,
                            title: "Add Images",
                            //buttons: {"Cancel": function() { $(this).dialog("close"); }},
                            draggable: false,
                            resizable: false 
                    });
                    $("#addImage").click(function() {
                         $.ajax({
                    url: "show.php", //it now afile where your function is and you want to run
                     type: "GET",        
                    data: data,  //any data you want to send to php file/function   
                  cache: false,
                 success: function (html) {  

                //add the content retrieved from ajax and put it in the #content div
                $('#dialog-form').html(html); //will add the content from the  php to div 
            }       
        });
                        $( "#dialog-form" ).dialog("open");
                        return false;
                    });
                    });
        <button id="addImage">Add Image</button>
            <div id="dialog-form"> <?php function show_php(); ?>
            </div>