Access JSON object returned from server-side processing

Access JSON object returned from server-side processing

BigBobBigBob Posts: 3Questions: 0Answers: 0
edited December 2012 in General
Hi,

I would like to access JSON object returned by DataTable from PHP script. Right now I can add some data to the JSON (in PHP) like this
[code]
$output = array(
"table_header"=>$header,
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => 0,
"iTotalDisplayRecords" => 0,
"aaData" => array()
);

echo json_encode( $output );
[/code]
and DataTables process it just fine (despite the additional item), but I can't find a way to read the returned object in javascript. Any idea how should I proceed to read the value of 'table_header' from the above code sample? Thank you.

Replies

  • BigBobBigBob Posts: 3Questions: 0Answers: 0
    Never mind, I found it here http://datatables.net/forums/discussion/2891/how-to-use-the-server-side-callback-for-post-processing/p1 so I just added
    [code]
    "fnServerData": function(sSource, aoData, fnCallback){
    $.ajax({
    "dataType": 'json',
    "type": "GET",
    "url": sSource,
    "data": aoData,
    "success": function(result){
    $('#tbl_header').text(result.table_header);
    fnCallback(result);
    }
    });
    }
    [/code]
    to the initialization and everything's good.
This discussion has been closed.