php – 将动态数据传递给bootstrap模式
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 将动态数据传递给bootstrap模式,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1481字,纯文字阅读大概需要3分钟。
内容图文
![php – 将动态数据传递给bootstrap模式](/upload/InfoBanner/zyjiaocheng/700/21b94c3f59844ff0ba8757afbf28bdde.jpg)
我试图在模态上加载特定帖子的评论.为此,我需要将post id传递给模态,然后获取相应的注释.
模态由以下内容触发:
<a class="xyz" data-toggle="modal" data-target="#compose-modal" data-id="<?php echo $list[$i]->getID(); ?>">View Comments</a>
模式在页面底部定义如下:
<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- here i need to use php to fetch the comments using post id -->
</div>
</div>
</div>
解决方法:
在页面返回浏览器之前执行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来触发模态:
<a class="xyz" onclick = "launch_comment_modal(<?php echo $list[$i]->getID(); ?>)">View Comments</a>
然后,在底部与您的其他JavaScript:
<script>
$('#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
},
});
}
</script>
内容总结
以上是互联网集市为您收集整理的php – 将动态数据传递给bootstrap模式全部内容,希望文章能够帮你解决php – 将动态数据传递给bootstrap模式所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。