title: incorporate json object into datatables
body: <p>I have json data that's being imported to a page where I am trying to create a datatable.</p>
  
  <p>the <code>console.log(jsonReturn)</code>:</p>
  
  <pre><code> {"1":{"dateReceived":"1905-07-04","cost":"2.7200","number":"757991"},"2":{"dateReceived":"1905-07-04","cost":"2.7200","number":"757991"}}
  </code></pre>
  
  <p>Below is my var <code>jsonReturn</code>:</p>
  
  <pre><code>Array
  (
      [1] =&gt; Array
          (
              [dateReceived] =&gt; 1905-07-04            
              [cost] =&gt; 2.7200
              [number] =&gt; 757991
  
          )
  
      [2] =&gt; Array
          (
              [dateReceived] =&gt; 1905-07-04
              [cost] =&gt; 2.7200
              [number] =&gt; 757991
  
          )
  
      [3] =&gt; Array
          (
              [dateReceived] =&gt; 1905-07-04
              [cost] =&gt; 2.7200
              [number] =&gt; 757991
  
          )
  
  )
  </code></pre>
  
  <p>I've read through every example on the DataTables website and I can't find anything on how to utilize this variable to fill my table.  Apart from initializing the table:</p>
  
  <pre><code>$(document).ready(function(){    
      var table = $('#ltc-table').dataTable( {
      "aaData" : jsonReturn,   
  });
  </code></pre>
  
  <p>Setting <code>aaData</code> to <code>jsonReturn</code> loads something into my table, but it's just gibberish.  I need to know how to tell DataTables exactly where to find the data I want it to use to populate the table, and which rows I want to display where, etc.</p>
  
  <p>I arrive at this javascript var by doing the following:</p>
  
  <p>The user searches with a text-box, which goes off to an ajax call.</p>
  
  <pre><code>$.ajax({
        type: 'POST',
        url: 'quoteManagerSearch.php',      
        data: {searchBy:searchBy, searchValue:searchValue, options:options},        
          success:function(data){                
          jsonReturn = data;
          $("#quoteReturn").load("return.php");
          //$("#quoteReturn").html(data);                                            
          }
    }); //close ajax call
  
  
  $searchQuery  = "SELECT * FROM alldata where $searchBy like '%$searchValue%'" ;
  $searchResult = mysqli_query($con, $searchQuery);
  
  $x = 0;
  while ($row = mysqli_fetch_row($searchResult)) {
  
  $x = $x + 1;
  
  
      $output[$x]["dateReceived"] = convertDate($row[1]);
      $output[$x]["cost"] = $row[15];
      $output[$x]["number"] = $row[16];
      }
  
  
  echo json_encode($output);
  </code></pre>
  
  <p>on success, <code>return.php</code> is loaded into a div, and <code>var jsonReturn</code> is created.</p>
  
  <p>Then, in <code>return.php</code> I try to use my invalid object. </p>
  
  <h1>Update</h1>
  
  <p>In response to @davidkonrad's post:</p>
  
  <p>I'm getting the following error now:</p>
  
  <pre><code>DataTables warning: JSON data from server could not be parsed.  This is caused by a JSON formatting error.
  </code></pre>
  
  <p>From what I can see (minus the quotation marks,) my JSON string looks exactly like yours.</p>
  
  <pre><code>{"aaData":[ 
    {"dateReceived":"1905-07-04","cost":"2.7200","number":"757991"},
    {"dateReceived":"1905-07-04","cost":"2.9200","number":"337995"}
    ]
  }
  </code></pre>
  
  <p>I also changed <code>DataTable</code> to <code>dataTable</code> since I'm using 1.9.4 for this test.</p>
  
  <h1>Update #2</h1>
  
  <p><strong>I figured out what's going wrong!</strong></p>
  
  <p>The process, as I saw it, is as follows:</p>
  
  <ol>
  <li><p>User loads quoteManager.php, and enters options in a textbox, then hits <code>search</code>.  This value is converted into a javascript var, and sent off in this ajax call:</p>
  
  <pre><code>$.ajax({
  type: 'POST',
  url: 'quoteManagerSearch.php',      
  data: {searchBy:searchBy, searchValue:searchValue, options:options},        
    success:function(data){                
    jsonReturn = data;
    $("#quoteReturn").load("quoteManagerReturn.php");
    }
  </code></pre>
  
  <p>}); //close ajax call</p></li>
  <li><p>quoteManagerSearch.php is the actual query against the database.  This outputs a valid JSON string.</p></li>
  </ol>
  
  <p>in <code>quoteManager.php</code>, there is a <code>&lt;div&gt;</code> at the bottom of the page for this response to load into:</p>
  
  <pre><code>&lt;div id="quoteReturn"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <ol start="3">
  <li><p>I do something wrong here.</p></li>
  <li><p><code>quoteManagerReturn.php</code> is loaded into the <code>#quoteReturn</code> div on the <code>quoteManager.php</code> page - but without any of the data that <code>quoteManagerSearch.php</code> returned, because <code>quoteManagerReturn.php</code> is running its own ajax to <code>quoteManagerSearch.php</code> - not using the one I ran in the beginning, and this string, <code>$searchBy = $_POST['searchBy'];</code> is empty - so I get no results.  This is why it's telling me my JSON is invalid, because it's empty!</p></li>
  <li><p>What I need to do (which I'm not sure how to do...)</p>
  
  <ol>
  <li>Use <code>jsonReturn</code> in <code>quoteManagerReturn.php</code> - as this is the valid JSON response I want, instead of making a <strong>new</strong> ajax request to <code>quoteManagerSearch.php</code>, or</li>
  <li>Pass these variables over from <code>quoteManager.php</code> to <code>quoteManagerReturn.php</code>and send them in the ajax request I'm making from <code>quoteManagerReturn.php</code> to <code>quoteManagerSearch.php</code>.</li>
  </ol></li>
  </ol>
  
  <h1>Update 2++</h1>
  
  <p>I sorted this out by just adding the variables into my ajax call on the second page:</p>
  
  <pre><code>var table = $('#ltc-table').DataTable( {    
        ajax : { 
         url : 'quoteManagerSearch.php' ,       
         dataSrc : 'aaData' ,
         type : 'POST',
         data: {searchBy:searchBy, searchValue:searchValue, options:options},
        },    
  </code></pre>
  
  <p>I've taken the original ajax call out of my first page (since there's no reason for the duplication...) <strong>I believe this is the solution!</strong></p>