title: select box notice Uncaught TypeError:Cannot read property 'DepCod' of undefined
body: <p>google chrome notice "Uncaught TypeError:Cannot read property 'DepCod' of undefined"</p>
  
  <p>Please fix my code and tell me why is my code does not work</p>
  
  <pre><code>$.ajax({
      url:base_url + 'c_category/departList',
      data:'',
      dataType: "text",
      cache:false,
      type:'post',
      success: function(dep){
      if(dep !== ''){    
      var re = $.parseJSON(dep);
      var counts = dep.length;               
      var i = 0;
  
      for(i=0;i&lt;counts;i++){
      $.each(re ,function(index,value){
            $("#deps").append("&lt;option value="+value[i].DepCod+"&gt;"+value[i].DepLocNam+&lt;/option&gt;");
      //  alert(value[dep][0].DepCod);
  
      });
      }
      } else {
      $('.dep').html("no data"); 
      }
      },
      error:function(){
      $('.dep').html("error"); 
      }
      });
  </code></pre>
  
  <p>this is my controller</p>
  
  <pre><code>    function departList(){
  
      $query['dep'] = $this-&gt;m_category-&gt;getAllDepart();
      echo json_encode($query);
      }
  </code></pre>
  
  <p>and model</p>
  
  <pre><code>    function getAllDepart(){
  
      $this-&gt;db-&gt;select("*");
      $this-&gt;db-&gt;from('DEPMST');              
      $query = $this-&gt;db-&gt;get();      
      return $query-&gt;result();            
      }
  </code></pre>
  
  <p>and bootstrap html</p>
  
  <pre><code>    &lt;div class="col-md-2"&gt;
      &lt;div class="dep" &gt;
      &lt;select id="deps" name="dep" class="form-control"&gt; 
      &lt;option value="0"&gt;--- dep list---&lt;/option&gt;
      &lt;/select&gt;
      &lt;/div&gt;    
      &lt;/div&gt;
  </code></pre>
  
  <p>thank you everybody i can fix it out like this</p>
  
  <pre><code>var re = $.parseJSON(dep);
  $.each(re.dep,function(index,value)
  {           
  $("#deps").append("&lt;option value="+value.DepCod+"&gt;"+value.DepLocNam+"&lt;/option&gt;");
  });
  </code></pre>