Error in Jquery DataTable "Requested unknown parameter '0' for row 0, column 0."

1

Good people, I have been presented with this error and I have not been able to solve it, I hope you can help me:

This is my PHP code in which I get my DB records     

include ("conexion.php");

$query = "SELECT * FROM ciclos;";
$resultado = mysqli_query($conexion, $query);

if (!$resultado){
    die("Error");       
}else{
    $array["data"] = []; 
    while( $data = mysqli_fetch_assoc($resultado)){
        $arreglo["data"][] =  array_map("utf8_encode",$data);
    }
    echo json_encode($arreglo);
}
mysqli_free_result($resultado);
mysqli_close($conexion);
?>  

This is my code that I have in the HTML:

<script>        
    $(document).on("ready", function(){
        listar();
    });
    var listar = function(){
        var table = $("#ciclos").DataTable({
            "ajax":{
                "method":"POST",
                "url": "listar.php"
            },
            "colums":[
                {"data":"ciclo"},
                {"data":"fecha_inicio"},                    
                {"data":"fecha_termino"}
            ],
            "language" : idioma_espaniol
        });
    }
    var idioma_espaniol = {
"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>

HTML code of the table:

    <div class="row">
    <div id="cuadro1" class="col-sm-12 col-md-12 col-lg-12">
        <div class="col-sm-offset-2 col-sm-8">
            <h3 class="text-center"> <small class="mensaje"></small></h3>
        </div>
        <div class="table-responsive col-sm-12">        
            <table id="ciclos" class="table table-bordered table-hover" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>Ciclo</th>
                        <th>Fecha de Termino</th>
                        <th>Fecha de Inicio</th>                            
                        <th></th>
                    </tr>
                </thead>                    
            </table>
        </div>          
    </div>      
</div>

The file listar.php shows the data:

The message that is thrown is the following:

    
asked by Miguel Angel 09.08.2017 в 17:51
source

1 answer

1

When using the columns option you have to make sure you have the same number of columns in the JavaScript file and in the HTML table.

The solution to this problem may be:

  • add / remove an object data , or
  • add / remove header cell <th> of the table

depending on whether one of these elements is missing or missing.

Also, at the start of your PHP file you could indicate that the answer uses the JSON format by modifying the HTTP header with the following line:

header('Content-Type: application/json; charset=utf-8');
    
answered by 09.08.2017 / 19:46
source