データベースから州を選択ボックスに入力するフォームで、州の選択都市に基づいて選択ボックスの下に入力する必要があります。codeigniterを使用してこれを行うにはどうすればよいですか。ajaxの方法を試しましたが、「未定義」で機能していません。
function get_city(){
var state=$("#state").val();
var dataString = 's_id='+ state;
var url="<?php echo base_url()?>admin/home/get_city";
$.ajax({
type:"POST",
url:url,
data:dataString,
success:function(data){
$("#city").html(data);
}
});
}
コントローラ:
function get_city(){
$this->load->model('data_model');
$data['records']=$this->data_model->get_cities();
return $data['records'];
}
モデル:
function get_cities(){
$this->db->select('id','city');
$this->db->from('cities');
$this->db->where('s_id', $this->uri->segment(4));
$query=$this->db->get();
if($query->num_rows()>0){
foreach($query->result() as $row){
$data[]=$row;
}
return $data;
}
}
これについて助けが必要です