填充引导模式与内容,只是当点击


Populate bootstrap modal with content just when clicked

我有一个像这样的列表表,它是由php循环填充的

| **name**   | **age**  | **course** | **action**      |
| wilson     | 56       | Web pro    | edit  delete    |

编辑按钮看起来像

 <a href="<?php echo base_url()?>admin/edit/{$row['id']}" data-href="#myModal">Edit</a>

我有一个模态已经显示,当编辑被点击,但我想要的情况是,当我点击编辑按钮的url localhost/admin/edit/3,其中3是一个id运行和数据库查询获取用户的详细信息id = 3,并返回到视图,现在将填充到模态。

我知道这可能是ajax的东西但我真的不知道怎么做

可以发送一个参数为id的ajax请求,然后从Database中获取所需的数据。返回json编码的数据。然后使用javascript解码数据,然后根据需要在你的模式弹出框中填充它。

我正在使用codeigniter,所以很难实现这些建议,后来我通过这样做让它工作:

在触发模态的按钮上设置

:

 <a data-toggle="modal" href="<?php echo base_url(); ?>admin/profile/edit/<?php echo   $row['id']; ?>" class="btn btn-warning btn-xs" >Edit</a>

然后在我的代码下面我有:

<?php if(@$show_edit_modal): ?>
<script>$("#edit_modal").modal('show'); </script>
<?php endif;?>

在admin/profile/edit:

i had

public function profile($arg1="", $arg2=""){
if($arg1=='edit' && !(empty($arg2)){
$data['profile'] = my qyuery to get the row where id=$arg2;
$data['show_edit_modal']=true; //this set to true so when the page loads modal will pop up
$this->load->view('mypage'); //page loads and modal pops up then on modal i can access my data from database
}
}