我错过了什么?在“你确定你要删除”中的“确定”之后,我什么都没有得到。但是当我试图提醒$id时,它工作了。是 AJAX 的问题吗?
我在我的footer.php里有这个
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$('.confirm-delete').click(function (e) {
e.preventDefault();
confirmDialog = confirm("Are you sure you want to delete?");
if(confirmDialog)
{
var id = $(this).val();
// alert(id);
$.ajax({
type: "DELETE",
url: "/employee/confirmdelete/"+id,
success: function (response) {
alert("Data deleted successfuly");
}
});
}
});
});
</script>
我在我的routes.php里有这个
$route['employee/confirmdelete/(:any)']['DELETE'] = 'Frontend/EmployeeController/delete/$1';
我的删除按钮
<button type="button" class="btn btn-danger confirm-delete" value="<?= $row->id; ?> ">Confirm Delete</button>
我在控制器中的删除功能
public function delete($id)
{
$this->load->model('EmployeeModel');
$this->EmployeeModel->deleteEmployee($id);
redirect(base_url('employee'));
}
我模型删除功能
public function deleteEmployee($id)
{
return $this->db->delete('employee', ['id' => $id]);
}"
1条答案
按热度按时间juzqafwq1#
您应该更改此设置
对此