title: jQuery populate items into a Select using jQuery ajax json, php
body: <p>I have a select field. I must fill with options taken from a mysql table.<br>
  Here is some little php code I have done using codeigniter framework</p>
  
  <pre><code>$idcateg = trim($this-&gt;input-&gt;post('idcategory'));
  $array1 = array(
      'result' =&gt; $idcateg
  );
  echo json_encode($array1);
  </code></pre>
  
  <p>Now, the jQuery call...</p>
  
  <pre><code>$.post("&lt;?=base_url()?&gt;index.php/rubro/list_ajax/", { 
      'idcategory' : idc },
      function(data){
          alert(data.result);
      }, "json");
  </code></pre>
  
  <p>The code works fine. When I call the post, I get the categoryid as a result.<br>
  Now, I should modify the code above, so I can do:</p>
  
  <ul>
  <li>post the ajax call sending the category id. this is done</li>
  <li>get subcategories for this category, and build the array *</li>
  <li>json_encode the array and echo *</li>
  <li>get results back in jQuery ajax call, decode and build the &lt; select > field *</li>
  </ul>
  
  <p>The array should be built with each element having a sub-array with id and name, right?
  Thanks a lot in advance for any help</p>