【发布时间】:2022-06-21 20:11:34
【问题描述】:
我错过了什么? 在“你确定要删除”中的“确定”之后,我什么也没得到。但是当我尝试提醒 $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]);
}"
【问题讨论】:
标签: json ajax codeigniter codeigniter-3 sql-delete