我正在使用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>
然后我有以下功能: function show_php( echo“我需要在这里放PHP代码” ); 我如何调用函数show_php();这可能是使用jquery dialog();?
答案 0 :(得分:4)
$('#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({
......
});
答案 1 :(得分:0)
使用查询对话框的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
}
});
答案 2 :(得分:0)
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>