title: Populating select box depending on above select box selected in codeigniter
body: <p>I a form where state is populated in select box from db, and based on state selection city must be popualted in below select box. Can any one help me on this how can i do this using codeigniter.I tried ajax way but it's not working 'undefined'.</p>
  
  <pre><code>function get_city(){
  var state=$("#state").val();
  var dataString = 's_id='+ state;
  var url="&lt;?php echo base_url()?&gt;admin/home/get_city";
  
  
  $.ajax({
      type:"POST",
      url:url,
      data:dataString,
      success:function(data){
  
         $("#city").html(data);
     }
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Controller:</p>
  
  <pre><code>function get_city(){
  
  
      $this-&gt;load-&gt;model('data_model');
      $data['records']=$this-&gt;data_model-&gt;get_cities();
  
      return $data['records'];
  
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>    function get_cities(){
  
      $this-&gt;db-&gt;select('id','city');
      $this-&gt;db-&gt;from('cities');
      $this-&gt;db-&gt;where('s_id', $this-&gt;uri-&gt;segment(4));
  
      $query=$this-&gt;db-&gt;get();
      if($query-&gt;num_rows()&gt;0){
          foreach($query-&gt;result() as $row){
              $data[]=$row;
  
          }
          return $data;
      }
  }
  </code></pre>
  
  <p>I need help on this</p>