Get data with WHERE_IN in CodeIgniter Sending Array with Ajax from Vista

0

I'm not very expert in the subject, I'm in the beginning. what I want is to obtain model data with an array sent with the category IDs to the controller through an AJAX request, the category IDs grouped in an array in Javascript as follows:

var categoriadata = new Array();
function filter(categoriad) {
if(categoriad>0){categoriadata.push(categoriad);}					    $.ajax({
 type: 'POST',
 url: '<?php echo base_url(); ?>productos/PaginacionData',
 data:'categoriadata='+categoriadata,
 success: function (html) {
		$('#productlist').html(html);
	}
});
}
<input onclick="filter(<?= $categprod->id ?>);" type="checkbox">

And in the controller I receive the data to move to the Model:

function PaginacionData(){
  $condicion = array();
  $condicion['buscar']['categ'] = $this->input->post('categoriadata');
  // Busco datos en el modelo pasando las condiciones
  $data['productos'] = $this->producto_model->getDatos($condicion);
  //Cargo ala vista
  $this->load->view('productos/paginacion-data', $data, false);
}

In the model I receive and try to obtain the data with WHERE_IN in the following way:

function getDatos($params = array()){
  $this->db->select('*');
  $this->db->from('productos');
  $this->db->where_in('category_id',array($params['buscar']['categ']));
  $this->db->order_by('id','desc');
  $query = $this->db->get();
  return $query->result_array();
}
    
asked by Pedro Cutire 03.01.2019 в 18:00
source

0 answers