title: DataTables warning: invalid JSON response when there are no records in the table. Also added empty array but records are not displaying
body: <p>I am using CodeIgniter with the bootstrap data table to display the records from the database. </p>
  
  <p>I am getting the error when there are no records are available in the table.</p>
  
  <blockquote>
    <p>DataTables warning: table id=employee-List - Invalid JSON response.
    For more information about this error, please see
    <a href="http://datatables.net/tn/1" rel="nofollow noreferrer">http://datatables.net/tn/1</a></p>
  </blockquote>
  
  <p>Records are displaying when available in the table. </p>
  
  <p>(<strong>Note</strong>: If I added empty array instated of 0 in the model then my error goes of but records are not displaying from the database.)</p>
  
  <p>I tried to find out the solution on SO but none of the solutions is working for me. Can anyone assist me what's the issue with my code?</p>
  
  <p><a href="https://i.stack.imgur.com/nihxo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nihxo.png" alt="enter image description here"></a></p>
  
  <p>My code is,</p>
  
  <p><strong>Script</strong></p>
  
  <pre><code>$('#employee-List').DataTable({
    language: {
      sLengthMenu: "Show _MENU_", // remove entries text
      searchPlaceholder: "Search",
      emptyTable: "No record found",
      search: ""
    },
    "ordering": false, // remove sorting effect from header 
    "processing": true,
    "serverSide": true,
    "scrollX": true,
    "bInfo": false,
    "pageLength": 10,
    "ajax": {
      "url": baseUrl + "/Employee_control/fetch_employeeList",
      "type": "POST"
    },
    "columns": [{
        "data": "id",
        "className": "reg_bg"
      },
      {
        "data": "name"
      },
      {
        "data": "email"
      },
      {
        "data": "mobileno"
      },
      {
        "data": "emp_id"
      },
      {
        "data": "address"
      },
      {
        "data": "action"
      }
    ]
  
  });
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function fetch_employeeList(){
    $order_list=$this-&gt;Employee_model-&gt;fetch_employeeList();
  
  // Datatables Variables
  $draw = intval($this-&gt;input-&gt;get("draw"));
  $start = intval($this-&gt;input-&gt;get("start"));
  $length = intval($this-&gt;input-&gt;get("length"));
  
  $data['draw'] = 1;
  $data['recordsTotal'] = count($order_list);
  $data['recordsFiltered'] = count($order_list);
  foreach ($order_list as $key =&gt; $row) 
  {
  $action='&lt;a href="" class="action-btn action-btn-border"&gt;View&lt;/a&gt;&lt;a href="" class="action-btn action-btn-red-bg"&gt;Archive&lt;/a&gt;';
  $arr_result = array(
              "id" =&gt;$row-&gt;id,
              "name" =&gt; $row-&gt;firstname." ".$row-&gt;middlename." ".$row-&gt;lastname,
              "email" =&gt; $row-&gt;email_id,
              "mobileno" =&gt; $row-&gt;mobileno,
              "emp_id" =&gt; $row-&gt;employee_id,
              "address" =&gt; $row-&gt;address,
              "action" =&gt; $action
  );
  
  $data['data'][] = $arr_result;
  
  }
  //print_r($arr_result);
  echo json_encode($data);
  exit;
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public function fetch_employeeList(){
          $this-&gt;db-&gt;select('*');
        $this-&gt;db-&gt;from('tbl_employee');
  
          $query = $this-&gt;db-&gt;get();
          $result = $query-&gt;result();
          if($result)
        {
            return $result;
        }
        else{
            return []; //I added empty array instated of 0. Using this my error goes of but records are not displaying from the database.
        }
      }
  </code></pre>