Help with JSON error when searching with server side script

Help with JSON error when searching with server side script

doppoppdoppopp Posts: 2Questions: 0Answers: 0
edited June 2012 in General
Hi!

I was hoping to get some help with a problem related to doing a search on my table.
Im getting an invalid response saying that my JSON is invalid.

Now here's my JSON:
[code]
{"sEcho":11,"iTotalRecords":1614,"iTotalDisplayRecords":0,"aaData":[null]}
[/code]

I know that the 'null' shouldnt be in the aaData set, but I cant seem to properly remove it.
Here's the relevant PHP script:
[code]
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);

while ( $aRow = sqlsrv_fetch_array( $rResult ) )
{

$row = array();

for ( $i=0 ; $i

Replies

  • doppoppdoppopp Posts: 2Questions: 0Answers: 0
    I think I actually fixed it by doing:
    [code]If (!empty($row)) { $output['aaData'][] = $row; }[/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Im getting an invalid response saying that my JSON is invalid.

    If you are getting the warning about invalid JSON, then that is coming from jQuery, because it can't parse the JSON returned. If you encounter that again, perhaps you can run the table through the DataTables debugger in that state so we can see what is happening.

    Allan
This discussion has been closed.