dropdown filter using codeigniter php, ajax response html
dropdown filter using codeigniter php, ajax response html

hiii, I want to make a filter dropdown using codeigniter ...
but I want to make an ajax response in the form of html ... because the fields I will create will be dynamic ...
**for before I have tried it using 'native php' and it works but when I tried it on codeigniter it didn't work..
-ajax code-
$(document).ready(function(){
$('#example').DataTable();
$("#periode1").on('change', function(){
var value = $(this).val();
$.ajax({
url: "<?= base_url('Kriteria/getPost'); ?>",
type: 'POST',
data: 'request='+value,
success:function(data)
{
$("#tampil_kriteria").html(data);
$('#example').DataTable();
},
});
});
});
this is my php code..
-dropdown-
<div class="col-md-3">
<select name="periode" id="periode1" class="browser-default custom-select" tabindex="-1" aria-hidden="true">
<?php foreach($periode as $per): ?>
<option value="<?php echo $per['id_periode'] ?>"><?php echo $per['keterangan'] ?></option>
<?php endforeach ?>
</select>
</div>
-controller-
public function index()
{
$data['title'] = 'Manajemen Data';
$data['title2'] = 'Daftar Kriteria';
$data['user'] = $this->Kriteria_model->getUserById();
$data['periode'] = $this->Kriteria_model->getAllPeriode();
$id = $this->Kriteria_model->getId();
$data['kriteria'] = $this->Kriteria_model->getAllKriteria($id);
$this->load->view('templates/header', $data);
$this->load->view('templates/menu', $data);
$this->load->view('kriteria/index', $data);
$this->load->view('templates/footer');
}
public function getPost()
{
$id = $this->input->post('request');
if($id){
$data['kriteria2'] = $this->Kriteria_model->getAllKriteria($id);
return $this->load->view('kriteria/tampil_kriteria', $data);
} else {
$id = $this->Kriteria_model->getId();
$data['kriteria'] = $this->Kriteria_model->getAllKriteria($id);
$this->load->view('kriteria/index', $data);
}
$this->load->view('templates/footer');
}
-model-
public function getAllKriteria($id)
{
return $this->db->get_where('kriteria', ['id_periode' => $id])->result_array();
}
thank you before for help..
This discussion has been closed.
Replies
@allan @collin
I'm not clear on how this is a DataTables question I'm afraid. It appears to be specifically about how to use CI, which I'm afraid we can't help with. You'd be best asking on a CI forum or StackOverflow.
Allan