I am using HMVC with CodeIgniter 3 and I need to list some datas in a certain select
, based on other select
.
So far I have this method in my Modelos
controller, that is intended to be used to populate the second select
:
public function select_by_id_marca()
{
$data = array();
$this->db->order_by($this->primary_key, 'DESC');
$this->db->get_where('marca', array('id' => $this->input->post('hdn_id_marca')));
$query = $this->db->get($this->table);
foreach ($query->result_array() as $row) {
$data[] = $row;
}
$query->free_result();
return $data;
}
And this is the Ajax:
$('#id_marca').change(function() {
var selectedId = $(this).find('option:selected').val();
$('#hdn_id_marca').attr('value', selectedId);
$.ajax({
url: '/admin/modelos/select_by_id_marca',
data: selectedId,
type: 'POST',
success: function() {
}
});
});
I am actually facing too a 500 Internal Server Error
when changing the first #id_marca
, but I also need a solution to make this work. Thank you.