bootstrap和php交互,php – 将动态数据传递给bootstrap模式

我试图在模态上加载特定帖子的评论.为此,我需要将post id传递给模态,然后获取相应的注释.

模态由以下内容触发:

View Comments

模式在页面底部定义如下:

解决方法:

在页面返回浏览器之前执行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来触发模态:

View Comments

然后,在底部与您的其他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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值