我想通过提供一个警告框来删除我在数据库中的记录,该警告框是bootstrap模式框。 我正在使用codeigniter,我试过但它没有用。请帮助..
这是我的控制器:
function deleteImage($id = NULL){
$this->config_mdl->delete_image($id);
$this->session->set_flashdata('msg', 'Image Deletion Successful !!');
}
这是我的模特:
function delete_image($id)
{
return $this->db->delete('tbl_gallery', array('image_id' => $id));
}
这是我的观点:
<div id="confirmDelete" class="modal fade" role="dialog" aria-lebelledby="confirmDeleteLebel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure want to delete this record?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-sm" id="confirm">OK</button>
<button type="button" class="btn btn-warning btn-sm" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<div class="caption img-gallery-caption">
<?php
$attributes = array('data-toggle' => 'modal', 'data-target' => '#confirmDelete', 'data-title' => 'Delete Image', 'data-message' => 'Are you sure you want to delete this Image?');
echo anchor('config/editImage', '<i class="glyphicon glyphicon-edit"></i>', $attributes);
echo anchor('config/deleteImage/'.$image->image_id, '<i class="glyphicon glyphicon-trash"></i>');
?>
</div>
这是我的Javascript代码:
<script type="text/javascript">
$("#confirmDelete").on('show.bs.modal', function(e){
$(this).find('#confirm').attr('href', $(e.relatedTarget).data('href'));
});
</script>
答案 0 :(得分:0)
首先确保您可以进入$("#confirmDelete").on...
您可以在通话中使用ajax
$("#confirmDelete").on('show.bs.modal', function(e){
// Search the 'id'
$.post(
'deleteImage/'+id,
'',
funcion(data){
// some data tha you want to receive from the server
},
'json');
});
答案 1 :(得分:0)
您正在设置按钮的href值!按钮没有href属性,所以改为将按钮转换为锚标记,它会起作用!