将动态数据传递给引导模式

我试图在模态上加载特定post的评论。 为此,我需要将post id传递给modal,然后获取相应的注释。 模态由以下触发:

<a class="xyz" data-toggle="modal" data-target="#compose-modal" data-id="getID(); ?>">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底部:

   

只需通过带有php页面的ajax传递内容并回显模态中的内容