title: Subcategories with Ajax and Codeigniter
body: <p>I have select box with categories and I want to display subcategories in another select box using ajax an CodeIgniter.</p>
  
  <p>This is part of my view:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  
      $('#tip_category').change(function(){
          msg = 'category_id='+$(this).val();
              $.ajax({
                  type : 'POST',
                  url : '&lt;?php echo base_url().'admin/tips/ajax_subcategory';?&gt;',
                  data : msg
  
  
      });
      });    
  });
  
  &lt;/script&gt;
  
  Category:&lt;br/&gt;
  &lt;select name="tip_category" id="tip_category"&gt;
      &lt;?php foreach($categories as $category): ?&gt;
          &lt;option value="&lt;?php echo $category['id'] ?&gt;"&gt;&lt;?php echo $category['name'] ?&gt;
          &lt;/option&gt;    
      &lt;?php endforeach; ?&gt;
  &lt;/select&gt;&lt;br/&gt;
  
  Subcategory:&lt;br/&gt;
  &lt;select name="tip_subcategory"
      &lt;?php if(isset($subcategories)): ?&gt;
          &lt;?php foreach($subcategories as $subcategory): ?&gt;
              &lt;option value="&lt;?php echo $subcategory['id'] ?&gt;"&gt;&lt;?php echo $subcategory['name'] ?&gt;
              &lt;/option&gt;    
          &lt;?php endforeach; ?&gt;
      &lt;?php endif; ?&gt;
  &lt;/select&gt;&lt;br/&gt;
  </code></pre>
  
  <p>This is part of my controller:</p>
  
  <pre><code>public function ajax_subcategory() {
      $this-&gt;load-&gt;model('tips_model');
      $data['subcategories'] = $this-&gt;tips_model-&gt;get_subcategories($this-&gt;input-&gt;post('category_id'));     
  }
  </code></pre>
  
  <p>My problem is that i dont know how to send data ($data['subcategories']) back to view and display subcategories. Thx for help !</p>