title: PHP-AJAX: How to populate jquery datatables from a query through php / json array
body: <p>I've just started to look into <a href="https://www.datatables.net/" rel="nofollow noreferrer">Datatables jQuery Plugin</a> and I'm having a it of a hard time getting it to work with my current work.</p>
  
  <p>I normally populate tables using an AJAX callback by getting the values I want from an array, querying the database through a PHP script. For what I've read on the datatables website, something similar is possible but I keep getting errors so I'll just post what I've done so far in hopes someone can help me out.</p>
  
  <p>This is how I call the databale with some ajax parameters.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready( function () {
      $('#test_table').DataTable({
          "processing": true,
          "serverSide": true,
          "ajax": {
              "url": "test.php",
              "type": "POST"
          },
          "columns": [
              { "data": "id" },
              { "data": "name" },
              { "data": "email" }
          ]
      });
  } );
  &lt;/script&gt;
  </code></pre>
  
  <p>This is what the php side looks like.</p>
  
  <pre><code>$sql = "SELECT * FROM test_table";
  $res = mysqli_query($conn, $sql) or die("Error: ".mysqli_error($conn));
  
  $columns = array(
              array('db' =&gt; $row['id'], 'dt' =&gt; 'id'),
              array('db' =&gt; $row['name'], 'dt' =&gt; 'name'),
              array('db' =&gt; $row['email'], 'dt' =&gt; 'email'),
      );
  
  echo json_encode($columns);
  </code></pre>
  
  <p>however, I get an error saying that "data is not defined". (notice. I read the documentation on the datatables website but I did not exactly followed it step by step. I used this as a reference for what I'm trying to accomplish. <a href="https://datatables.net/examples/server_side/post.html" rel="nofollow noreferrer">Datatables Server Side POST</a></p>
  
  <p>I am probably going all wrong about this but I didn't want to change my code too much, so I tried an approach I thought would work. If anyone could enlighten me on how to populate datatables by querying the database from a php > json array call, I'd be very grateful.</p>
  
  <p>Thanks in advance,</p>