非常簡單直接的解決方案是;
如果您正在使用jQuery UI Dialog
僅供參考,頁面名稱index.php
和顯示數據庫獲取數據(如問題陳述)
更換data-target="#modal_<?php echo $id;?>"
與class="open" id="<?php echo $id; ?>"
綁定open
選擇器jQuery click function
$(".openmodal").click(function();
創建變量id
並從按鈕屬性中獲取id="<?php echo $id; ?>"
。
var id = $(this).attr("id");
使用Ajax Method模態
莫代爾打開按鈕來獲取對id
和顯示數據將
<tr>
<td><button class="open" id="<?php echo $id; ?>">show first</button></td>
<td><?php echo $name; ?></td>
</tr>
和模態的HTML將
<div id="dialog" style="display:none;">
<div id="Schedule"></div> //Here we show the content in Modal
</div>
和Ajax方法將
$(document).ready(function(){
$(".openmodal").click(function() {
var id = $(this).attr("id");
alert(id);
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "ajax.php",
data: dataString,
cache: false,
success: function(data) {
$("#dialog").dialog();
$("#Schedule").html(data);
}
});
});
});
現在創建ajax.php
在阿賈克斯的方法來使用;
<?php
//connection to the database
if($_POST['id']) {
$id = $_POST['id'];
//Run Query to fetch the data against `$id`
?>
//This form with fetched detail from database will show in Modal
<form action="" name="" class="" id="">
<input type="text" value="<?php echo $variable; ?>">
<input type="submit" value="submit">
</form>
<?php } ?>
如果你正在使用bootstrap modal您可以檢查this answer。
你使用'jQuery ui modal-dialog'嗎? – Shehary
是的......我從AdminLTE基本代碼開發 – FireFoxII
我發佈解決方案作爲答案,看看它是否有幫助,任何問題,隨時問 – Shehary