Table not filled using JSON correct data - no error
Table not filled using JSON correct data - no error
Hi, everyone. I would like to have some help.
I'm trying to use datatables in Wordpress, because I have some custom tables to draw in template of page.
My table is not moving, just printing the div "Processing...". I've already checked my JSON response thanks to http://jsonlint.com/, it's correct one. Thus, I can't understand why It doesn't work, no error in console and valid JSON...
Here is my js code :
[code]
jQuery(document).ready(function($) {
$('#json-test').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./get_data.php" // The file is accessed
});
});
[/code]
Here is my get_data.php code :
[code]
require('../../../wp-blog-header.php'); // I'm using wordpress object wpdb to access database
global $wpdb;
$sOutput = array('sEcho'=>intval($_GET['sEcho']),
'iTotalRecords'=>155, // Trust me, I don't filter the datas, and there are 155 rows.
'iTotalDisplayRecords'=>155);
$aaData = array();
$list_annonc = $wpdb->get_results("SELECT * FROM view_fcl_liste_annonceurs_inscrits");
foreach ($list_annonc as $annonc_row){
$tmp = array();
$tmp[] = addslashes($annonc_row->numan);
$tmp[] = addslashes($annonc_row->valid);
$tmp[] = addslashes($annonc_row->papier);
$tmp[] = addslashes($annonc_row->societe);
$tmp[] = addslashes($annonc_row->ville);
$aaData[] = $tmp;
}
$sOutput['aaData'] = $aaData;
wp_send_json($sOutput); // I tried to use "echo json_encode($sOutput); " also but It didn't work either.
[/code]
Do I need to make some more process on the JSON response ???
Thank you.
I'm trying to use datatables in Wordpress, because I have some custom tables to draw in template of page.
My table is not moving, just printing the div "Processing...". I've already checked my JSON response thanks to http://jsonlint.com/, it's correct one. Thus, I can't understand why It doesn't work, no error in console and valid JSON...
Here is my js code :
[code]
jQuery(document).ready(function($) {
$('#json-test').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./get_data.php" // The file is accessed
});
});
[/code]
Here is my get_data.php code :
[code]
require('../../../wp-blog-header.php'); // I'm using wordpress object wpdb to access database
global $wpdb;
$sOutput = array('sEcho'=>intval($_GET['sEcho']),
'iTotalRecords'=>155, // Trust me, I don't filter the datas, and there are 155 rows.
'iTotalDisplayRecords'=>155);
$aaData = array();
$list_annonc = $wpdb->get_results("SELECT * FROM view_fcl_liste_annonceurs_inscrits");
foreach ($list_annonc as $annonc_row){
$tmp = array();
$tmp[] = addslashes($annonc_row->numan);
$tmp[] = addslashes($annonc_row->valid);
$tmp[] = addslashes($annonc_row->papier);
$tmp[] = addslashes($annonc_row->societe);
$tmp[] = addslashes($annonc_row->ville);
$aaData[] = $tmp;
}
$sOutput['aaData'] = $aaData;
wp_send_json($sOutput); // I tried to use "echo json_encode($sOutput); " also but It didn't work either.
[/code]
Do I need to make some more process on the JSON response ???
Thank you.
This discussion has been closed.