我有数据表的情况,我不明白:
问题:
我有这个rewriteRule:
Rewriterule ^table/ table.php
所以,当我去 www.site.com/table.php 时,一切都很好,但是当我去 www.site.com/table / 时我有下一条提醒信息:
DataTables警告:table id = {tablet} - 无效的JSON响应。有关此问题的详细信息,请访问:http://datatables.net/tn/1
我去了建议网址,但我无法解决问题。
很抱歉,但由于是内部网,我无法将网站上线。
我的PHP代码是这样的:
$table = 'paciente';
$primaryKey = 'id';
$columns = array(
array(
'db' => 'id',
'dt' => 0),
array(
'db' => 'nombre',
'dt' => 1,
'formatter' => function( $d, $row ) {
$links='<a href="paciente/'.$row[0].'/0/">'.$row[1].'</a>';
return $links;
}),
array( 'db' => 'apellidos', 'dt' => 2 ),
array( 'db' => 'tel_mov', 'dt' => 3,
'formatter' => function( $d, $row ) {
$tels=$row[3];
return $tels;
}
),
array( 'db' => 'tel_casa', 'dt' => 4,
'formatter' => function( $d, $row ) {
$tels2=$row[4];
return $tels2;
}
),
array( 'db' => 'terapeuta', 'dt' => 5 ),
array(
'db' => 'id',
'dt' => 6,
'formatter' => function( $d, $row ) {
$links2='<a href="print-historia.php?height=655&width=800&id='.$row[0].'" class=" thickbox"><img src="ima/edit.png" /></a> | <a href="?borrar=total&id='.$row[0].'" onClick="return confirmSubmit()"><img src="ima/close.png" /></a>';
return $links2;
}),
);
require( 'libraries/ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
和javascript:
<script type="text/javascript" src="<?php echo $base; ?>js/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#tablet').DataTable({
"language": {
"url": "js/Spanish.json"},
"scrollY": "500px",
"scrollCollapse": true,
"pageLength": 25,
"processing": true,
"serverSide": true,
"ajax": "table-load.php",
"order": [[ 1, "asc" ]],
"aoColumns": [
{ "sTitle": "id","bVisible": false},
{ "sTitle": "Nombre" },
{ "sTitle": "Apellidos" },
{ "sTitle": "Móbil","bSortable": false },
{ "sTitle": "Fijo","bSortable": false },
{ "sTitle": "Terapeuta","bSortable": false },
{ "sTitle": "Edición","bSortable": false,"bSearchable": false }],
"fnDrawCallback": function() {
tb_init('a.thickbox');
}
});
} );
</script>
任何想法?在此先感谢!!
答案 0 :(得分:0)
我有类似的问题。问题是Datatable.js需要从数据&#34;数据中读取数据。数组键(诚实地在他们的文档中找到非常难的信息)。
这意味着您需要调整PHP脚本以获取具有此结构的数组:
"success" => true|false // useful to display errors
"message" => string // explains the error (if occurred)
"data" => array // contains all your data
修改强>
这是一个可以由DataTable.js编码和处理的PHP数组的示例。注意数组键&#34; data&#34;:DataTable.js将搜索要在jsonResponse.data中显示的元素。
<?php
// data fetched from database
$fromDatabase = [
'example',
'test',
'foo',
'bar'
];
$response = [
'success' => true,
'message' => '',
'data' => $fromDatabase
];
echo json_encode($response);
?>
答案 1 :(得分:0)
我使用ajax调用中的完整url在javascript DataTable选项中修复它:
"ajax": "<?php echo $base; ?>table-load.php"
所以javascript是这样的:
<script type="text/javascript" src="<?php echo $base; ?>js/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#tablet').DataTable({
"language": {
"url": "js/Spanish.json"},
"scrollY": "500px",
"scrollCollapse": true,
"pageLength": 25,
"processing": true,
"serverSide": true,
"ajax": "<?php echo $base; ?>table-load.php",
"order": [[ 1, "asc" ]],
"aoColumns": [
{ "sTitle": "id","bVisible": false},
{ "sTitle": "Nombre" },
{ "sTitle": "Apellidos" },
{ "sTitle": "Móbil","bSortable": false },
{ "sTitle": "Fijo","bSortable": false },
{ "sTitle": "Terapeuta","bSortable": false },
{ "sTitle": "Edición","bSortable": false,"bSearchable": false }],
"fnDrawCallback": function() {
tb_init('a.thickbox');
}
});
} );
</script>
和php:
$table = 'paciente';
$primaryKey = 'id';
$columns = array(
array(
'db' => 'id',
'dt' => 0),
array(
'db' => 'nombre',
'dt' => 1,
'formatter' => function( $d, $row ) {
$links='<a href="../paciente/'.$row[0].'/0/">'.$row[1].'</a>';
return $links;
}),
array( 'db' => 'apellidos', 'dt' => 2 ),
array( 'db' => 'tel_mov', 'dt' => 3,
'formatter' => function( $d, $row ) {
$tels=$row[3];
return $tels;
}
),
array( 'db' => 'tel_casa', 'dt' => 4,
'formatter' => function( $d, $row ) {
$tels2=$row[4];
return $tels2;
}
),
array( 'db' => 'terapeuta', 'dt' => 5 ),
array(
'db' => 'id',
'dt' => 6,
'formatter' => function( $d, $row ) {
$links2='<a href="../print-historia.php?height=655&width=800&id='.$row[0].'" class=" thickbox"><img src="ima/edit.png" /></a> | <a href="?borrar=total&id='.$row[0].'" onClick="return confirmSubmit()"><img src="ima/close.png" /></a>';
return $links2;
}),
);
require( 'libraries/ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
请注意,我将../
置于网址
这对我有用......