title: Datatables and ajax data formatting?
body: <p>I am using Datatables and I want to be able to send an AJAX request to get my data.</p>
  
  <p><strong>My jQuery -</strong> </p>
  
  <pre><code>$('.valid-tags').DataTable( {
      "ajax": {
          "url": "/ajax/getValidTags.php",
          "type": "POST",
          "data": {
              ruleID: ruleID
          }
      }
  } );
  </code></pre>
  
  <p><strong>This is the data returned from the ajax request -</strong></p>
  
  <pre><code>{"data":["K":2,"B":1,"C":2]}
  </code></pre>
  
  <p>Im expecting to see 'K', 'B', 'C' under tag name in their own rows.</p>
  
  <p><a href="https://i.stack.imgur.com/4ZS6j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ZS6j.png" alt="enter image description here"></a></p>
  
  <p>My Datatables doesn't load any data though?</p>
  
  <p>I need to be able to wrap each key value pair in its own array so this -</p>
  
  <pre><code>{"data":["K":2,"B":1,"C":2]}
  </code></pre>
  
  <p>Would be -</p>
  
  <pre><code>{"data":[["K":2],["B":1],["C":2]]}
  </code></pre>
  
  <p>This is the PHP that builds it (where do i wrap the key values in an object so it like the above)?-</p>
  
  <pre><code>$validTagsArray = array();
  $validArray = array();
  
  foreach ($cursor as $key =&gt; $value) {
    foreach ($value['AutoFix'] as $k =&gt; $v) {
      $x = 0;
      foreach ($v as $key =&gt; $value) {
        $x++;
        $validValueCount = $validTagsArray[$k] = $x;
      }
    }
  }
  
  $validArray['data'] = array($validTagsArray);
  
  
  echo json_encode($validArray);
  </code></pre>