我正在尝试通过在数据表中选中多个复选框并单击按钮来删除数据库中的多个ID。我有以下代码,但收到错误400(错误请求)http://localhost/ra/member/ajax_delete/ 1615,1614 其中1615,1614是我要删除的ID,这是我的代码:
观点:
....
<td><input type="checkbox" name="id[]" value="'.$paket->id.'"/></td>
....
<button type="button" value="Click" id="btntest">Delete All</button>
<script type="text/javascript">
$(document).ready(function() {
function getCheckboxesValues(){
return [].slice.apply(document.querySelectorAll("input[type=checkbox]"))
.filter(function(c){ return c.checked; })
.map(function(c){ return c.value; });
}
document.getElementById("btntest").addEventListener("click", function(){
delete_paket(getCheckboxesValues());
});
function delete_paket(id)
{
// ajax delete data to database
$.ajax({
url : "<?php echo site_url('member/ajax_delete')?>/"+id,
type: "POST",
dataType: "JSON",
success: function(data)
{
//if success reload ajax table
$('#modal_form').modal('hide');
reload_table();
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error deleting data');
}
});
}
})
}
</script>
控制器:
public function ajax_delete($id)
{
$this->load->model('mem_data','paket')
$this->paket->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
模特:
public function delete_by_id($id)
{
$this->db->where_in('id', $id);
$this->db->delete($this->table);
}
我的代码仅适用于1个复选框,不适用于多个复选框,请帮助我