title: CodeIgniter - jQuery, JSON, simple example not working
body: <p>Ok, Im a real newbie when it comes to ajax and json ... Im trying to figure it out in my codeigniter project.</p>
  
  <p>Ive written something simple to start, just to bring up an alertbox, but it doesnt seem to be working, if someone could let me know where im going wrong, that would be grand.</p>
  
  <p>In my view i have the following code.</p>
  
  <pre><code>$('.users').change(function(){
      $.ajax({
          type: "POST",
          url: "/edituser/returndata",
          data: {id: this.find(':selected').val()},
          dataType: json,
          success: function(data){
              alert(data);
          }
      });
  });
  </code></pre>
  
  <p>in the edituser/returndata controller, i just simply have the following</p>
  
  <pre><code>function returndata(){
      echo $_POST['id'];
  }
  </code></pre>
  
  <p>I know this will look pretty stupid to some people, but im still trying to figure it out, if someone could help :)</p>
  
  <p>Cheers</p>
  
  <p>----------------- UPDATED CODE BELOW</p>
  
  <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt;
  $('#users').live('change', function(){
  
      $.ajax({
          type: "POST",
          url: "/edituser/returndata",
          data: {id: $(':selected', this).val()},
          dataType: 'json',
          success: function(data){
              alert(data.id);
          }
      });
  });                     
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller code</p>
  
  <pre><code>function returndata()
  {
      $ID = $this-&gt;input-&gt;post('id');  // Use this instead of $_POST['id']
      echo json_encode(array('id'=&gt;$ID));
  }
  </code></pre>