I am trying to list data from a table using datatables but I am getting the error
"Uncaught TypeError: Cannot read property 'length' of undefined"
And I dont know why. I appreciate any help as I am new in this kind of programs.
My html:
<table class="table mg-b-0 table-contact" style="width:100% !important;" id="preEnrolTable">
<thead>
<tr>
<!--<th class="wd-5p">
<label class="ckbox mg-b-0">
<input type="checkbox"><span></span>
</label>
</th>-->
<th class="tx-10-force tx-mont tx-medium">DNI</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Nombre</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Tarjeta</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Clave</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Privilegio</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Huella</th>
<th class="tx-10-force tx-mont tx-medium hidden-xs-down">Rostro</th>
<th class="wd-5p hidden-xs-down"></th>
</tr>
</thead>
</table>
This is the script that should bring the data:
function getPreEnrol() {
$("#preEnrolTable").DataTable().clear();
$("#preEnrolTable").DataTable().destroy();
var table = jQuery("#preEnrolTable");
var oTable = table
.on('preXhr.dt',function(e,settins,data){
$("#modalLoadText").html('Estamos cargando la información, espere un momento!');
$("#modalLoad").modal('show');
})
.dataTable({
"processing": false,
"autoWidth": false,
"paging": true,
"pageLength": 5,
"serverSide": true,
"order": [
[0, 'asc']
],
"ajax": {
"url": "SYS_include/WS/PreEnrolamiento/WS_PreEnrolamiento.php",
"data": {
"getDatos":true
}
}
...
And this is the script that is being called in the ajax url:
$Permisos = new Permisos();
$pagina=45;
$modulo=3;
$i = $Permisos->traerPermisos($json,$pagina,$modulo);
$preEnrol = new PreEnrolamiento();
//error_log($_GET["getDatos"]); // devuelve true
//error_log(print_r($_GET["getDatos"])); // devuelve 1
if(isset($_GET["getDatos"]) && !empty($_GET["getDatos"])){
switch ($i) {
case 1:
case 2:
case 3:
case 4:
case 5:
echo $preEnrol->getPreEnrolamientos($instancia,$sucursal,$conn);
break;
}
}else if(isset($_POST["getNac"]) && !empty($_POST["getNac"])){
switch ($i) {
case 1:
case 2:
case 3:
case 4:
case 5:
$nacionalidades = Dni::obtenerNacionalidades($instancia,$conn);
echo json_encode($nacionalidades);
break;
}
}