【问题标题】:why cascading is not working in country and state为什么级联在国家和州不起作用
【发布时间】:2017-09-23 20:00:34
【问题描述】:

enter image description here

enter image description here

为什么会发生这种情况,它们分别是视图模型控制器。

我的代码没有运行,但它从数据库中获取数据。 我该如何解决这个问题,请帮助我。

提前致谢。

function getcountry()
    {
       $this->db->select('*');
       $query = $this->db->get('et_country');
       return $query->result();
    }

    function getstate($country_id='')
    {
       $array = array('status' => 'Active','country_id' => $country_id);
       $this->db->select('id,name,country_id');
       $this->db->where($array);
       $query = $this->db->get('et_state');
       return $query->result();
    }
    
    function getcity($state_id='')
    {
       $array = array('status' => 'Active','state_id' =>  $state_id);
       $this->db->select('id,name,state_id');
       $this->db->where($array);
       $query = $this->db->get('et_city');
       return $query->result();
    }
 public function create_subadmin()
    {
        $this->load->model('Auction_model');
        $data['country'] = $this->Auction_model->getcountry();           
        $this->load->view('admin/Auction/add_Auction',$data);   
    }
  
    public function ajax_state_list($country_id)
    {
        $this->load->model('Auction_model');
        $data['state'] = $this->Auction_model->getstate($country_id);
        $this->load->view('admin/Auction/add_Auction',$data);
    }
    
    public function ajax_city_list($state_id)
    {
        $this->load->model('Auction_model');
        $data['city'] = $this->Auction_model->getcity($state_id);
        $this->load->view('admin/Auction/add_Auction',$data);
    }
<script>
            function getstatedetails(id)
            {
                //alert('this id value :'+id);
                $.ajax({
                    type: "POST",
                    url: '<?php echo site_url('admin/Auction_controller/ajax_state_list').'/';?>'+id,
                    data: id='cat_id',
                    success: function(data){
                //        alert(data);
                        $('#old_state').html(data);
                    },
                });
            }
            </script>
            <script>
            function getcitydetails(id)
            {
                $.ajax({
                    type: "POST",
                    url: '<?php echo site_url('admin/Auction_controller/ajax_city_list').'/';?>'+id,
                    data: id='st_id',
                    success: function(data){
                       
                        $('#old_city').html(data);
                    },
                });
            }
                </script>
                
                <div class="form-group">
                                <label>Country</label><br>
                                <select name="country_id" class="form-control" id="country_details" onChange="getstatedetails(this.value)">
                                    <option value="<?php echo $rs->name ?>" selected="selected" >Select</option>
                                    <?php
                                    foreach ($country_id as $rs) {
                                        ?>
                                        <option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>State</label><br>
                                <select name="state_id" class="form-control" id="old_state" onChange="getstatedetails(this.value)">
                                    <option value="<?php echo $rs->name ?>" selected="selected" >Select</option>
                                    <?php
                                    
                                    foreach ($state_id as $rs) {
                                        ?>
                                        <option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>City</label><br>
                                <select name="city_id" class="form-control" id="old_city" onChange="getcitydetails(this.value)">
                                    <option value="" selected="selected" >Select</option>
                                    <?php
                                    foreach ($city_id as $rs) {
                                        ?>
                                        <option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
                                    <?php } ?>
                                </select>
                            </div>

【问题讨论】:

    标签: codeigniter model-view-controller


    【解决方案1】:

    尝试像这样更改 ajax 调用:

    变量值 = { 'cat_id': 身份证 };

    $.ajax({
                  url: "<?php echo site_url('admin/Auction_controller/ajax_state_list').'/';?>"+id,
                  type: "post",
                  data: values,
                  success: function(data) {
                       $('#old_state').html(data);
                  }
              });
    

    【讨论】:

    • 还是不行,请给我一些其他的答案
    • 当我选择国家时,它不会出现任何错误,它将获取国家,但它使国家选项为空。即使选择了任何国家
    • 我的控制器 url 是 controller/admin/auction_controller
    • 我的模特网址是model/admin/Auction_model
    • 我的查看网址是 view/admin/Auction/add_Auction
    猜你喜欢
    • 1970-01-01
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2021-11-15
    相关资源
    最近更新 更多