Datatable JSON Invalid JSON response

0

Why this error is due

  

DataTables warning: table id = Table_Tools - Invalid JSON   response For more information about this error, please see    link

I enclose a photo with the answer on my network

My code

// Call the dataTables jQuery plugin
$(document).ready(function() {
  var table = $('#Tabla_Herramientas').DataTable({

                "destroy": true,
                "processing": true,
                "ajax": {
                    "method": "POST",
                    "url": "Clases/JSON.php"
                },
                "order": [
               [0, "desc"]
              ],
                "columns": [
                {
                    "data": "Id"
                },{
                    "data": "Codigo"
                },{
                    "data": "Descripcion"
                },{
                    "data": "FechaIngreso"
                },{
                    "data": "Estado"
                },{
                    "data": "FechaAsignacion"
                },{
                    "data": "CodResponsable"
                },{
                    "data": "Nombre"
                },{
                    "data": null,
                    "defaultContent": ""

                }],

                "language": idioma_espanol
            });


});

var idioma_espanol = {    
       "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_ registros",
           "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"    
       }
   }

  </script>

JSON FILE

<?php



$mysqli = new mysqli(NOMBREHOST, USUARIO, PASSWORD, NOMBREBD);

$query     = "SELECT * from herramientas order by Id desc";
$resultado = $mysqli->query($query);
$tabla     = "";
while ($row = $resultado->fetch_assoc()) {
    $Codigo         = $row['Codigo'];
    $Descripcion    = $row['Descripcion'];
    $Estado         = $row['Estado'];
    $CodResponsable = $row['CodResponsable'];


    $query      = "SELECT * from herrasignada where Codigo='$Codigo'";
    $resultado2 = $mysqli->query($query);
    if ($res1 = $resultado2->fetch_assoc()) {
        $FechaAsignacion = $res1['FechaAsignacion'];
    } else {
        $FechaAsignacion = "0000-00-00";
    }

    if ($CodResponsable != NULL) {
        $sql        = "Select * from personal where Codigo=$CodResponsable";
        $resultado1 = $mysqli->query($sql);
        if ($res = $resultado1->fetch_assoc()) {
            $Nombre = $res['Nombre'];
        } else {
            $Nombre = "";
        }
    }

    $tabla .= '{"Id":"' . $row['Id'] . '","Codigo":"' . $row['Codigo'] . '","Descripcion":"' . $row['Descripcion'] . '","FechaIngreso":"' . $row['FechaIngreso'] . '","Estado":"' . $row['Estado'] . '",
"FechaAsignacion":"' . $FechaAsignacion . '","CodResponsable":"' . $CodResponsable . '","Nombre":"' . $Nombre . '"},';



}
$tabla = substr($tabla, 0, strlen($tabla) - 1);
echo '{"data":[' . $tabla . ']}';
//echo json_encode($arreglo,JSON_UNESCAPED_UNICODE);

mysqli_free_result($resultado);
mysqli_close($mysqli);
    
asked by MoteCL 01.08.2018 в 23:52
source

1 answer

2

You have an error in the structure of the JSON; change "language": idioma_espanol by "language": "idioma_espanol" .

You can validate your JSON here

Greetings!

    
answered by 02.08.2018 / 00:01
source