Typeerror D是未定义的Jquery数据表

时间:2015-07-26 15:55:32

标签: javascript jquery datatables

我有以下代码,用于使用数据表生成报告。但它继续失败给我以下jquery数据错误:

TypeError: d is undefined


...=f.nextSibling}else{d=b.anCells;f=0;for(b=d.length;f<b;f++)a(d[f])}return{data:e...

下面是我应该生成视图的代码,目前我只得到一个空白

<!DOCTYPE html>
<html lang="en">
    <head>
        <!--

        -->
        <meta charset="utf-8">
        <title>Care-tech System</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Out patient Hospital Management System.">
        <meta name="author" content="Harris Samuel Dindi">
    </head>
    <body>
        <table id="test_trial" class="test_trial">
            <thead>
                <tr></tr>
            </thead>
            <tbody>
                <tr></tr>
            </tbody>
        </table>
    </body>
</html>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="http://cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>

<link href='http://cdn.datatables.net/1.10.5/css/jquery.dataTables.css' rel='stylesheet'>



<script type="text/javascript">
    $(document).ready(function () {

        $("#test_trial").DataTable({
            stateSave: true,
            "bautoWidth": false,
            "aoColumns": [
                {"sTitle": "Commodity No", "mData": "commodity_id"},
                {"sTitle": "Commodity Name.", "mData": "commodity_name"

                },
                {"sTitle": "Strength", "mData": "strength"},
                {"sTitle": "Commodity code", "mData": "commodity_code"},
                {"sTitle": "Type.", "mData": "commodity_type"},
                {"sTitle": "Commodity unit", "mData": "commodity_unit"},
                {"sTitle": "Max Stock", "mData": "max_stock"},
                {"sTitle": "Min sTOCK", "mData": "min_stock"},
                {"sTitle": "Remarks", "mData": "remarks"},
            ],
            "bDeferRender": true,
            "bProcessing": true,
            "bDestroy": true,
            "bLengthChange": true,
            "iDisplayLength": 20,
            "sAjaxDataProp": "",
            "sAjaxSource": '<?php echo base_url() . "pharmacy/commodity_managements"; ?>',
            "aaSorting": [[2, "desc"]]

        });

    });
</script>

如何消除错误?

2 个答案:

答案 0 :(得分:2)

TypeError:d是未定义的,意味着您的服务器端php终结点URL(pharmacy / commodity_managements)不向网格返回任何数据。尝试调试您的php响应。

答案 1 :(得分:-1)

Ishettyl给出了一个部分正确的答案。数据表版本是最新版本,但正在使用的表属性来自旧版数据表。将所有表属性更改为1.10.5版本应该可以解决您的问题。 (例如:将“mData”更改为“data”,等等。)