weixin_33724059 2019-07-30 20:18 采纳率: 0%
浏览 28

未捕获的TypeError:数据表

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;
    }

}
  • 写回答

1条回答 默认 最新

  • weixin_33675507 2019-08-05 22:15
    关注

    Finally i found the solution to my problem, i will post it here if anyone need it, my ajax call:

    "ajax": {

                        "url": "SYS_include/WS/PreEnrolamiento/WS_PreEnrolamiento.php", 
                        "type":"get", //added
                        "dataType":'json', //added                  
                        "dataSrc": "", //added
                        "data":{"getDatos": true }
                          },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题