Codeigniter无法从动态下拉列表中获取价值

时间:2015-08-02 14:57:02

标签: jquery ajax codeigniter filter combobox

我使用ajax 动态下拉列表,我使用onchange="this.submit.form()"刷新所选值的数据。但是当我选择下拉列表时,我总是会收到错误Invalid argument supplied for foreach()。我认为这是因为null所以它显示错误。

这是视图

    <div class="col-lg-3">


    <div class="form-group">
    <br/>
        <b>AREA</b><br/>
        <?php echo form_dropdown('countriesDrp', $countryDrop,'','class="form-control" id="countriesDrp" required' );  ?>
        </select>
        </div>
        <div class="form-group">

        <b>RAYON</b>
        <div id='div_rayon'>
            <select name="cityDrp" id="cityDrp" class="form-control" onchange = "this.form.submit()" required>
    <option value=""></option>
    </select> `

这是我放置的地方:

<?php $nomor = 1; foreach ($pelayanan as $row) { echo '<tr> <td><center>'.$nomor.'</font></td> <td><center>'.$row['ID_AREA'].'</td> <td><center>'.$row['ID_RAYON'].'</td> <td><center>'.$row['N_RAYON'].'</td> <td><center>'.$row['ID_PEL'].'</td> <td><center>'.$row['NO_AGENDA'].'</td> <td><center>'.$row['TRANSAKSI'].'</td> <td><center>'.$row['LAMA'].'</td> <td><center>'.$row['ESTIMASI'].'</td> <td><center>'.$row['N_KENDALA'].'</td> <td><center>'.$row['DURASI_KENDALA'].'</td> <td>'; echo '<center><a class="btn btn-primary btn-sm" href="'.site_url('distribusi/pelayanan/verifikasi/'.$row['ID_PELAYANAN']).'" role="button"><span class="glyphicon glyphicon-ok" aria-hidden="true"></a></span>'; echo '<a class="btn btn-info btn-sm" href="'.site_url('distribusi/pelayanan/ubah/'.$row['ID_PELAYANAN']).'" role="button"><span class="glyphicon glyphicon-edit" aria-hidden="true"></a></span>'; // echo ' <a class="btn btn-danger" href="'.site_url('distribusi/penginapan/hapus/'.$row['idPenginapan']).'" role="button">Hapus</a> '</td> </tr>'; $nomor = $nomor + 1; } $nomor = 0; ?>

这是 javascript

        $(document).ready(function() { 


            $("#countriesDrp").change(function(){

                 /*dropdown post *///
                  $.ajax({
                url:"<?php echo base_url();?>index.php/distribusi/filter/buildDropCities",
                 data: {id: $(this).val()},
                type: "POST",
                success:function(data){

                    $("#cityDrp").html(data);
                }

                });

            });

        });

    </script>`

这是控制器

 public function daftar_verifdist($data=NULL, $post=NULL){


    $data['judul'] = "Pelayanan";
    $data['subjudul'] = "Data Pelayanan Tidak Sesuai Target";
    $data['pelayanan'] = $this->model_pelayanan->daftar_all_dist($data, $post);
    $data['user'] = $this->model_user->join();
    $data['countryDrop'] = $this->model_filter->getArea();

    $this->load->view('distribusi/start');
    $this->load->view('distribusi/header', $data);
    $this->load->view('distribusi/css_tabel');
    $this->load->view('distribusi/pelayanan_daftar', $data);
    $this->load->view('distribusi/footer');
    $this->load->view('distribusi/script_tabel');
    $this->load->view('distribusi/end');
}

这是模型

    $post_area = $this->input->post('countriesDrp');
    $post = $this->input->post('cityDrp');
    $data['ID_AREA'] = $post_area;
    $data['ID_RAYON'] = $post;

    $this->db->select('*');
    $this->db->from('pelayanan');
    $this->db->join('area', 'area.ID_AREA = pelayanan.ID_AREA', 'left');
    $this->db->join('rayon', 'rayon.ID_RAYON = pelayanan.ID_RAYON', 'left');
    $this->db->join('status', 'status.ID_STATUS = pelayanan.ID_STATUS', 'left');
    $this->db->join('kendala', 'kendala.ID_KENDALA = pelayanan.ID_KENDALA', 'left');
    $this->db->join('verifikasi', 'verifikasi.ID_VERIFIKASI = pelayanan.ID_VERIFIKASI', 'left');
    $this->db->where('pelayanan.ID_STATUS', '1');
    $this->db->where('pelayanan.ID_VERIFIKASI', '3');
    $this->db->like('pelayanan.ID_AREA', $data['ID_AREA']);
    $this->db->like('pelayanan.ID_RAYON', $data['ID_RAYON']);
    $this->db->order_by('ID_PELAYANAN', 'asc');
    $query = $this->db->get();

    if ($query->num_rows()) {
        return $query->result_array();
    } 
    else {
        return false;
    }

有人可以帮助我如何使用此动态下拉菜单从数据库中过滤数据吗? 谢谢

0 个答案:

没有答案