我试图在模态上加载特定帖子的评论.为此,我需要将post id传递给模态,然后获取相应的注释.
模态由以下内容触发:
模式在页面底部定义如下:
解决方法:
在页面返回浏览器之前执行PHP.一旦在浏览器中看到该页面,就已经执行了所有PHP.您可能想要做的是使用AJAX.以下是如何执行此操作的概述:
有一个PHP页面,它获取ID并返回您想要的数据作为JSON.
api.php
$theId = $_POST['theId'];
//Get the information you want, and turn it into an array called $data
header('Content-Type: application/json');
echo json_encode($data);
在你的html中,你应该使用附加到“查看注释”的onclick来触发模态:
然后,在底部与您的其他JavaScript:
$('#compose-modal').modal({ show: false});
function launch_comment_modal(id){
$.ajax({
type: "POST",
url: "api.php",
data: {theId:id},
success: function(data){
//"data" contains a json with your info in it, representing the array you created in PHP. Use $(".modal-content").html() or something like that to put the content into the modal dynamically using jquery.
$('#compose-modal').modal("show");// this triggers your modal to display
},
});
}
标签:php,jquery,modal-dialog
来源: https://codeday.me/bug/20191006/1858836.html