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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)