How to get 2D array in DataTable from json_encode($sOutString)
How to get 2D array in DataTable from json_encode($sOutString)
jewel03cse
Posts: 11Questions: 0Answers: 0
Hi, I have some fields in mysql database which contain value including ' , " , \n, \t etc. character. Hence I have used json_encode() function for encoding. But in the fnServerData(sSource, aoData, fnCallback){ }, how can I extract encoded value to get 2D array for using in datatable ?
Code segment in PHP:
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_POST['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
$serial=$_POST['iDisplayStart']+1;
$x="";
$y="";
$f=0;
while ( $aRow = mysql_fetch_array( $rResult ) )
{ if($f++) $sOutput .=',';
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['ID']).'",';
$sOutput .= '"'.$serial++.'",';
$sOutput .= '"'.addslashes($aRow['Upazila']).'",';
$sOutput .= '"'.addslashes($aRow['PAName']).'",';
$sOutput .= '"'.addslashes($aRow['UnderWH']).'",';
$sOutput .= '"'.addslashes($aRow['ComputerStatus']).'",';
$sOutput .= '"'.addslashes($aRow['UIMSoperational']).'",';
$sOutput .= '"'.addslashes($aRow['PrinterStatus']).'",';
$sOutput .= '"'.addslashes($aRow['Problem']).'",';
$sOutput .= '"'.addslashes($aRow['InternetStatus']).'",';
$sOutput .= '"'.addslashes($aRow['Remarks']).'",';
$sOutput .= '"'.$x.$y.'"';
$sOutput .= "]";
}
$sOutput .= '] }';
echo json_encode($sOutput);
[/code]
In java script
[code]
"fnServerData": function ( sSource, aoData, fnCallback )
{
aoData.push({"name":"operation", "value": "upazilaInfoListFetch"});
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});/// end of $.ajax()
}
[/code]
please give code example or link ?
Code segment in PHP:
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_POST['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
$serial=$_POST['iDisplayStart']+1;
$x="";
$y="";
$f=0;
while ( $aRow = mysql_fetch_array( $rResult ) )
{ if($f++) $sOutput .=',';
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['ID']).'",';
$sOutput .= '"'.$serial++.'",';
$sOutput .= '"'.addslashes($aRow['Upazila']).'",';
$sOutput .= '"'.addslashes($aRow['PAName']).'",';
$sOutput .= '"'.addslashes($aRow['UnderWH']).'",';
$sOutput .= '"'.addslashes($aRow['ComputerStatus']).'",';
$sOutput .= '"'.addslashes($aRow['UIMSoperational']).'",';
$sOutput .= '"'.addslashes($aRow['PrinterStatus']).'",';
$sOutput .= '"'.addslashes($aRow['Problem']).'",';
$sOutput .= '"'.addslashes($aRow['InternetStatus']).'",';
$sOutput .= '"'.addslashes($aRow['Remarks']).'",';
$sOutput .= '"'.$x.$y.'"';
$sOutput .= "]";
}
$sOutput .= '] }';
echo json_encode($sOutput);
[/code]
In java script
[code]
"fnServerData": function ( sSource, aoData, fnCallback )
{
aoData.push({"name":"operation", "value": "upazilaInfoListFetch"});
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});/// end of $.ajax()
}
[/code]
please give code example or link ?
This discussion has been closed.
Replies
Allan
Allan