2017-04-26 123 views
0

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>

回答

0

嘗試改變AJAX調用這樣的:

VAR值= { 'CAT_ID':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); 
       } 
      }); 
+0

它仍然無法正常工作,請你給我一些其他答案 –

+0

你會得到什麼錯誤?你可以檢查嗎? –

+0

它不會有任何錯誤發生的是當我選擇國家它會取得國家,但它使國家選項空白。即使在選擇任何國家 –