форма. php
массив (gettext ('Gateway Name'), array ("name" => "gateway_id", "class" => "gateway_id", "id" => " gateway_id "), 'SELECT', '', 'trim | required | xss_clean', 'tOOL TIP', 'Сначала выберите шлюз', 'id', 'name', 'gateways', 'build_dropdown', 'where_arr' , array ("status" => "0")),
view. php
$ (". gateway_routing_type"). change (function () {var gateway_routing_type = $ ( '.gateway_routing_type option: selected'). val ();
$.ajax({
type:'POST',
url: "<?= base_url() ?>/trunk/trunk_sipdevicelist/",
data:"gateway_routing_type="+gateway_routing_type,
success: function(response) {
var tmp = jQuery.parseJSON(response);
console.log(response);
$("#gateway_id").empty();
$.each(tmp, function(key, value) {
$("#gateway_id").append($('<option></option>').val(value.id).html(value.name));
});
$(".selectpicker").selectpicker('refresh');
}
});
});
контроллер. php
$ add_array = $ this-> input -> сообщение (); $ gateway_routing_type = $ add_array ['gateway_routing_type'];
$accountinfo = $this->session->userdata("accountinfo");
$gateway_array = array();
if($gateway_routing_type == "0"){
$gateway_result = $this->db->get_where('gateways', array(
"gateway_routing_type" => $gateway_routing_type,
"status" => 0
));
if ($gateway_result->num_rows() > 0) {
$gateway_result = $gateway_result->result_array();
foreach ($gateway_result as $key => $value) {
$gateway_array[] = array(
"id"=>$value['id'],
"name" => $value['name']
);
}
}
}else{
$this->db->select('GROUP_CONCAT(id) as provider_id');
$provider_id = (array)$this->db->get_where("accounts",array( "status"=>0,"deleted"=>0,"type"=>3 ))->first_row();
$array = explode("," ,$provider_id['provider_id']);
foreach($array as $value){
$sipdevice_result = $this->db->get_where("sip_devices",array("accountid"=>$value));
if ($sipdevice_result->num_rows() > 0) {
$sipdevice_result = $sipdevice_result->result_array();
foreach ($sipdevice_result as $key => $value) {
$gateway_array []= array(
"id"=>$value['id'],
"name" => $value['username']
);
}
}
}
}
когда происходит ajax вызов, он переходит в функцию, а затем показывает выбранное раскрывающееся значение