我正在设计一个页面,用户将在其中单击删除链接,应该出现一个模态来确认删除。但是当我单击模式上的确认按钮时,什么也没发生。
这是我的代码:
查看页面:
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="removeTeacherModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Remove Teacher</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="remove-messages"></div>
<p>Do you really want to remove ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="removeTeacherBtn">confirm</button>
</div>
</div>
控制器页面:
$button ='
<div class="dropdown text-center">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria- expanded="false">
Action
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><a class="dropdown-item" type="button" data-toggle="modal" data- target="#updateTeacherModal" onClick="editTeacher('.$value['staff_id'].')">Edit</a></li>
<li><a class="dropdown-item" type="button" data-toggle="modal" data- target="#removeTeacherModal" onClick="removeTeacher('.$value['staff_id'].')">Remove</a></li>
</div> ';
上面的部分是一个属性,之后将在页面上动态添加
此功能也包含在控制器页面中
public function removeT($teacherId = null){
$validator= array('success' => FALSE , 'messages' => array());
if($teacherId){
$remove= $this->model_staff->remove($teacherID);
if($remove){
$validator['success']=true;
$validator['messages']='Teacher is removed Successfully';
}
else{
$validator['success']=false;
$validator['messages']='Error while removing the information';
}
}
echo json_encode($validator);
}
型号:
public function remove($teacherId = null){
if($teacherId){
$this->db->where('staff_id', $teacherId);
$result = $this->db->delete('staff');
return ($result == true) ? true : false;
}
}
Javascript:
function removeTeacher(teacherId = null){
if(teacherId){
$('#removeTeacherBtn').unbind('click').bind('click', function() {
$.ajax({
url: base_url + 'staff/removeT/'+teacherId ,
type:'post',
dataType :'json' ,
success: function(response){
if (response.success == true){
$('#messages').html('<div class="alert alert-success alert-dismissible fade show" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria- label="Close"><span aria-hidden="true">×</span></button>'+ response.messages +
'</div>');
manageTeacherTable.ajax.reload(null,false);
$('#removeTeacherModal').modal('hide');
}
else {
$('#remove-messages').html('<div class="alert alert- warning alert-dismissible fade show" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria- label="Close"><span aria-hidden="true">×</span></button>'+ response.messages +
'</div>');
}
}
});
});
}
}