I am currently working on a program that uses php jquery and bootstrap, I want to delete multiple data using checkbox. I search and found out that it must use AJAX to passing the paramater from view to controller. The Jquery work find and can get the value from checkbox. But when I use Ajax, the button not working. Nothing change. Please help me to find the problem on my code. Thank you
My Controller
public function hapusbeberapa()
{
$this->model_security->getsecurity();
$this->load->model('model_barang');
$arr = $this->input->post('data');
//$arrcode= json_encode($arr);
foreach($arr as $id)
{
$query = $this->model_barang->getID($id);
if($query->num_rows()>0)
{
$this->model_barang->getdelete($id);
//$this->session->set_flashdata('info',"Data Berhasil Dihapus");
}
}
}
My Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_barang extends CI_model {
public function getdelete($key)
{
$this->db->where('IDBarang',$key);
$this->db->delete('tBarang');
}
public function getID($key)
{
$this->db->where('IDBarang',$key);
$query = $this->db->get('tbarang');
return $query;
}
}
My View
<script src="<?php echo base_url();?>http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#btnhapus").click(function(){
var favorite = [];
$.each($("input[name='checkboxlist']:checked"), function(){
favorite.push($(this).val());
});
$.post("<?php echo site_url(barang/hapusbeberapa) ?>"+actMult, {data:favorite}););
});
});
</script>
</script>
actMultin the url you're passing in$.post();