Access JSON object returned from server-side processing
Access JSON object returned from server-side processing
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.
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.
This discussion has been closed.
Replies
[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.