title: codeigniter get data via ajax and json from db
body: <p>I have following problem:</p>
  
  <p>View:</p>
  
  <pre><code>&lt;script&gt;
          function show(id) {
  
              $.ajax({
                  url: '&lt;?php echo site_url('index.php/controller/show_id'); ?&gt;',
                  dataType: 'json',
                  data:({id: id}),
                  type: "POST",
                  success: function (data) {
                      alert( data.user_id);
                  }
  
              });
          }
  
          &lt;/script&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>function show_id(){
  
              $id= $this-&gt;input-&gt;post('id');
              $id_list = $this-&gt;id_model-&gt;show_id($id);   
              $data['id'] = $id_list;
              if($data['id']){   
                   echo json_encode( $data['id'] );
              } else {
                   echo json_encode( array('error' =&gt; true) );
              }   
          }
  </code></pre>
  
  <p>If I load the page, I got "undefined" as an alert.
  If I change the JS to "alert(data);" I receive all content of the sql table. <br><br>
  How do I have to change the JS to get only "user.id" column?</p>