Message error with json
Message error with json

Hi datatable sayme this DataTables warning: table id=DataTables_Table_1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1 when i charge this data
public function mostrarTablaAreas()
{
$item = null;
$valor = null;
$areas = ControladorArea::ctrMostrarArea($item, $valor);
if (count($areas) == 0) {
echo '{"data"}: []}';
return;
}
$datosJson = '{
"data": [';
for ($i = 0; $i < count($areas); $i++) {
$botones = "<div class='btn-group'><button class='btn btn-warning btn-sm btnEditarArea' idArea='" . $areas[$i]["ID_Area"] . "' data-toggle='modal' data-target='#modalEditarArea'><i class='fas fa-pencil-alt text-white'></i></button><button class='btn btn-danger btn-sm btnEliminarArea' idArea='" . $areas[$i]["ID_Area"] . "'><i class='far fa-trash-alt'></i></button></div>";
$datosJson .= '[
"' . $areas[$i]["ID_Area"] . '",
"' . $areas[$i]["nombreArea"] . '",
"' . $botones . '"
],';
}
$datosJson = substr($datosJson, 0, -1);
$datosJson .= ']
}';
echo $datosJson;
}
Correctly table should say no data available but i have that error pls help me
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
**Here is my javascript **
$('.tablaAreas').DataTable({
"ajax": "ajax/datatable_areas_ajax.php",
"info": false,
"lengthMenu": [1, 3, 5, 10, 25, 50],
"pageLength": 3,
"retrieve": true,
"deferRender": true,
"processing": true,
language: {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar MENU registros",
"sZeroRecords": "No se encontraron resultados",
"sEmptyTable": "Ningún dato disponible en esta tabla =(",
"sInfo": "Mostrando registros del START al END de un total de TOTAL",
"sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered": "(filtrado de un total de MAX registros)",
"sInfoPostFix": "",
"sSearch": "Buscar:",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
},
"buttons": {
"copy": "Copiar",
"colvis": "Visibilidad"
}
}
});
Did you follow the steps at the link provided in the error?
http://datatables.net/tn/1
What is the JSON response?
Kevin