title: Display data using json in datatables codeigniter
body: <p>I want to display my data using json data format in datatables, but I am not getting any data in the table. Could anyone help me to display data in datatable through JSON?</p>
  
  <p>This is my controller:</p>
  
  <pre><code>public function data_courses(){
      $result=$this-&gt;Users_model-&gt;get_active_courses();
      echo json_encode($result);
  }
  public function courses_list(){
      $this-&gt;authentication();
      $this-&gt;load-&gt;view('courses');
  }
  </code></pre>
  
  <p>This is my view:</p>
  
  <pre><code>&lt;table class="table table-striped table-hover table-bordered" id="allcourses"&gt;
      &lt;thead&gt;
          &lt;tr role="row"&gt;
              &lt;th&gt;
                  Course Name
              &lt;/th&gt;
              &lt;th&gt;
                  Indian Price
              &lt;/th&gt;
              &lt;th&gt;
                  U S Price
              &lt;/th&gt;
              &lt;th&gt;
                  Course Duration
              &lt;/th&gt;
              &lt;th&gt;
                  Discount
              &lt;/th&gt;
              &lt;th&gt;
                  &lt;center&gt;Pick Course&lt;/center&gt;
              &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This is my script:</p>
  
  <pre><code>$(document).ready(function() {
      $('#allcourses').dataTable({
          "aLengthMenu": [
                  [5, 15, 20, 100, -1],
                  [5, 15, 20, 100, "All"]
              ],
   "ajax": "Student/data_courses",
          "aoColumns": [
              {"data": "course_name"},
              {"data": "price_INR"},
              {"data": "price_USD"},
              {"data": "no_of_hours"},
              {"data": "discount"},
              {"data": "status"},
              { "bSortable": false }
          ]
      });
  });
  </code></pre>
  
  <p>This is my model</p>
  
  <pre><code>public function get_active_courses(){
       $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('courses');
      $this-&gt;db-&gt;where('status',1);
      $query=$this-&gt;db-&gt;get();
      return $query-&gt;result();    
      }
  </code></pre>
  
  <p>My JSON data</p>
  
  <pre><code>{"data":[{"course_id":"1","course_name":" PHP","price_INR":"25,000","price_USD":"750","no_of_hours":"86","date":"2016-05-19 17:58:47","status":"1","discount":"5.89"},{"course_id":"5","course_name":"Java","price_INR":"15,000","price_USD":"650","no_of_hours":"25","date":"2016-05-14 07:59:24","status":"1","discount":"2.50"},{"course_id":"6","course_name":"Dot net","price_INR":"23,000","price_USD":"250","no_of_hours":"36","date":"2016-05-14 12:16:33","status":"1","discount":"5.63"},{"course_id":"7","course_name":"python","price_INR":"15000","price_USD":"650","no_of_hours":"78","date":"2016-05-14 19:25:34","status":"1","discount":"2.50"},{"course_id":"9","course_name":"HTML &amp; CSS","price_INR":"28,000","price_USD":"980","no_of_hours":"78","date":"2016-05-14 19:31:16","status":"1","discount":"2.36"}]}
  </code></pre>