我有一个显示组名等的table
和一个显示成员列表的modal
。当我单击一个特定的组名时,模态显示..我在ajax的成功函数中设置了modal的值,但是它没有显示任何东西..我也尝试在ajax的成功函数中做alert(response)
但警报没有出现。
这是我的代码: 对于HTML表:
<div class="row table-responsive">
<table class="table table-bordered table-striped table-condensed" id="r_data">
<thead class="header">
<tr class="well">
<th style="font-size: 14px;">
Group Name
</th>
<th style="font-size: 14px;">
Leader's Name
</th>
</tr>
</thead>
<tbody>
<?php if($result != NULL){?>
<?php foreach($result as $row){?>
<tr>
<td data-toggle="modal" href="#viewMember" data-id="<?php echo $row->reservedID;?>">
<?php echo $row->groupName;?>
</td>
<td>
<?php echo $row->l_name.", ".$row->f_name." ".$row->m_name;?>
</td>
</tr>
<?php }?>
<?php }?>
</tbody>
</table>
这是模态:
<div class="container" >
<div class="row">
<div class="modal fade" id="viewMember" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content"><!--CONTENT-->
<div class="form-horizontal"><!--Horizontal-->
<div class="modal-header"><!--HEADER-->
<button class="btn btn-primary close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="header"></h4>
</div><!--END of HEADER-->
<div class="modal-body"><!--BODY-->
<div class="welll">
<table class="table table-bordered table-striped table-condensed table-responsive" id="records_table">
<thead class="header">
<tr class="well">
<th>
Member's Name
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div><!--End of BODY-->
</div><!--END of Horizontal-->
</div><!--END of CONTENT-->
</div>
</div>
</div>
</div>
JS:
$('.viewMember').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var id = button.data('id')
$.ajax({
url: "<?php echo base_url('admin/group/getMember')?>",
type: 'POST',
data: { 'groupID': id},
dataType: 'JSON',
success: function(result){
//alert("hi");
$('.modal-body #header').text(result[0].fname);
}
});
});
控制器:
public function getMember(){
$data = array();
$id = $_REQUEST['groupID'];
$this->load->model('group_model');
$data = $this->group_model->getAllMember($id);
echo json_encode($data);
}
答案 0 :(得分:0)
首先,我没有看到与此代码$('.modal-body #header')
匹配的html元素。那么现在,我在显示输出方面会混淆你的问题。我假设你想要在标题<h4 id="header"></h4>
中显示。如果是,则在成功块中更改jquery代码,如下所示:
$('.modal-header').find('#header').html(result[0].fname);
如果显示要显示输出的位置,则可以轻松选择jquery。