title: Codeigniter Ajax Datatable showing Error
body: <p>I have referred this link to make my codeigniter datatable ajax based datatable.</p>
  
  <blockquote>
    <p><a href="http://mbahcoding.com/tutorial/php/codeigniter/codeigniter-simple-server-side-datatable-example.html" rel="nofollow noreferrer">http://mbahcoding.com/tutorial/php/codeigniter/codeigniter-simple-server-side-datatable-example.html</a></p>
  </blockquote>
  
  <p>But it is showing error and not showing the data in datatable.</p>
  
  <p><strong>Message: Undefined index: length</strong></p>
  
  <p><strong>Message: Undefined index: start</strong></p>
  
  <p><strong>Message: Undefined index: draw</strong></p>
  
  <p>Please someone help me to remove these errors. </p>
  
  <p>My Jquery</p>
  
  <pre><code>$(document).ready(function(){
        //Ajax Datatable
        //datatables
      var dataTable = $('#dataTables-suburb').DataTable({ 
  
          processing: true, //Feature control the processing indicator.
          serverSide: true, //Feature control DataTables' server-side processing mode.
          order: [], //Initial no order.
  
          // Load data for the table's content from an Ajax source
          ajax: {
              url: "&lt;?php echo site_url('admin/states/state_table_ajax')?&gt;",
              type: "POST"
          },
  
          //Set column definition initialisation properties.
          columnDefs: [
          { 
              targets: [ 0 ], //first column / numbering column
              orderable: false, //set not orderable
          },
          ],
  
  
      });  
  }); 
  </code></pre>
  
  <p>My Controller Function</p>
  
  <pre><code>public function state_table_ajax()
      {
         $data['details'] = $this-&gt;LoginModel-&gt;admin_details($this-&gt;session-&gt;userdata('admin-username'));
         foreach($data['details'] as $detail):
         $country_id = $detail['country_id'];
      endforeach;
          $states = $this-&gt;StatesModel-&gt;get_states_table($country_id);
  
          $no = $_POST['start'];
  
          foreach($states as $state):
              $no++;
              $row = array();
              $row[] = $no;
              $row[] = $state['id'];
              $row[] = $state['state_name'];
              //$row[] = '&lt;button type="button" name="update" id="'.$state['id'].'" class="btn btn-warning btn-xs"&gt;Update&lt;/button&gt;';  
              //$row[] = '&lt;button type="button" name="delete" id="'.$state['id'].'" class="btn btn-danger btn-xs"&gt;Delete&lt;/button&gt;';  
              $state_data[] = $row;
          endforeach;
  
          $output = array(
                  "draw" =&gt; $_POST['draw'],
                  "recordsTotal" =&gt; $this-&gt;StatesModel-&gt;get_states_count($country_id),
                  "recordsFiltered" =&gt; $this-&gt;StatesModel-&gt;get_states_count_filtered($country_id),
                  "data" =&gt; $state_data,
          );
          //echo "&lt;pre&gt;";
          //print_r($output);
          //output to json format
          echo json_encode($output);
      }
  </code></pre>
  
  <p>My Model Code</p>
  
  <pre><code>public function get_states($country_id)
      {
          $order_column = array('id', 'state_name');
          $this-&gt;db-&gt;select('id, state_name')
                             -&gt;where('country_id', $country_id, FALSE)
                             -&gt;from('tbl_states');
  
          //For Search value Datatable
          if(isset($_POST['search']['value'])) 
          {
              $this-&gt;db-&gt;like('state_name', $_POST['search']['value']);
          }
          //For Order Datatable
          if(isset($_POST['order']))
          {
              $this-&gt;db-&gt;order_by($this-&gt;order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
          }
          else  
          {  
              $this-&gt;db-&gt;order_by('id', 'DESC');  
          }
  
          //$result = $query-&gt;result_array();
          //return $result;
      }
      //Get Datatable
      public function get_states_table($country_id)
      {
          $this-&gt;get_states($country_id);
          if($_POST["length"] != -1)
          {
              $this-&gt;db-&gt;limit($_POST["length"], $_POST["start"]);
              $query = $this-&gt;db-&gt;where('country_id', $country_id, FALSE)
                                -&gt;get();
              return $query-&gt;result_array();
          }
      }
      function get_states_count_filtered($country_id)
      {
          $this-&gt;get_states($country_id);
          $query = $this-&gt;db-&gt;where('country_id', $country_id, FALSE)
                            -&gt;get();
          return $query-&gt;num_rows();
      }
      public function get_states_count($country_id)  
      {  
         $this-&gt;db-&gt;where('country_id', $country_id, FALSE)
                  -&gt;from('tbl_states'); 
  
  
         return $this-&gt;db-&gt;count_all_results();
      } 
  </code></pre>
  
  <p>Thank you in advance.</p>