title: How to read from json data from jquery using codeigniter
body: <p>I want to use jquery to get courses from the database when i click the level dropdown control.</p>
  
  <p>The Jquery code in my view</p>
  
  <pre><code>   &lt;script type="text/javascript"&gt;
      function getcourses()
      {
      var clevel = $('#clevel').val();
      var did = $('#did').val();
      var tday = $('#tday').val();
      var csrf_value = $('input[csrf_test_name]').val();
      var postdata = {
          'clevel': clevel,
          'did': did,
          'day': tday,
          'csrf_value': csrf_value
      };
  
      $.ajax({
          type: 'POST',
          url: 'http://localhost:8056/timetable/Admin/GetTbCourse/',
          data: postdata,
          datatype: 'json',
          success: function(result){
              $("#tm4_5").val(result.tbcourses['t0405']);
  
          },
          error: function (jqXHR, textStatus, errorThrown) {
              alert("Status " + jqXHR.status);
          }
      });
  }
  </code></pre>
  
  <p>The controller code</p>
  
  <pre><code>public function GetTbCourse() {
  
      $day = $this-&gt;input-&gt;post('day');
      $dept = $this-&gt;input-&gt;post('did');
      $clevel = $this-&gt;input-&gt;post('clevel');
  
      $getcourse = $this-&gt;MTimetable-&gt;ListTime($day, $dept, $clevel);
  
  
      $this-&gt;data['tbcourses'] = $getcourse;
       json_encode($this-&gt;data);
  
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>please how do i get the result sent by my controller to put in the text field one of which is</p>
  
  <pre><code>&lt;input type="text" class="form-control" id="tm2_3" name="tm2_3" /&gt;
  </code></pre>
  
  <p>Thanks</p>