【问题标题】:jQuery DataTable is not showing the datajQuery DataTable 没有显示数据
【发布时间】:2013-02-01 14:45:43
【问题描述】:

我的 jQuery DataTable 没有列出 JSON 数据。这是为什么呢?

HTML 代码:

<!doctype html>
<html lang="tr">
 <head>
    <meta charset="utf-8">
    <title>Binalar</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
        <style type="text/css" title="currentStyle">
            @import "http://127.0.0.1/HCAWebApp/DataTables-1.9.4/media/css/demo_page.css";
            @import "http://127.0.0.1/HCAWebApp/DataTables-1.9.4/media/css/demo_table.css";
        </style>
    <script src="http://127.0.0.1/HCAWebApp/DataTables-1.9.4/media/js/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="http://127.0.0.1/HCAWebApp/DataTables-1.9.4/media/js/jquery.dataTables.js"></script>

    <script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('#binalar').dataTable({
            "bProcessing" : true,
            "bServerSide" : true,
            "sAjaxSource" : "http://127.0.0.1/HCAWebApp/index.php/getbuildings"
        });
    }); 
</script>

    <style>
        body { padding: 15px 30px; }
        .alignleft { float: left; vertical-align:text-bottom; }
        .alignright { float: right; vertical-align:text-bottom; }
        td { width: 25% }
    </style>
 </head>
 <body>
                   <div class="navbar">
              <div class="navbar-inner">
                <div class="container">
                  <a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </a>
                  <div class="nav-collapse collapse navbar-responsive-collapse">
                    <ul class="nav">
                    <li class='active'><a href="binalar">Binalar</a></li>
                    <li ><a href="cihazlar">Cihazlar</a></li>
                    <li ><a href="kullanicilar">Kullanıcılar</a></li>
                    <li ><a href="gruplar">Gruplar</a></li>

                    </ul>
                    <ul class="nav pull-right">
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">İlhan ŞUBAŞI <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                          <li><a href="#">Veritronik</a></li>
                          <li><a href="#">Seller</a></li>
                          <li class="divider"></li>
                          <li><a href="kullanicilar/logout">Çıkış</a></li>
                        </ul>
                      </li>
                    </ul>
                  </div><!-- /.nav-collapse -->
                </div>
              </div><!-- /navbar-inner -->
            </div><!-- /navbar --><div class='fdfg'>
    <div id="baslik">
        <h1 style="margin-bottom:-15px" class="alignleft">Binalar</h1>
        <h3 style="margin-bottom:-15px" class="alignright">+ Bina Ekleme</h3>   </div>
    <div style="clear: both;"></div>
    <hr>

    <table cellpadding="0" cellspacing="0" border="0" class="display" id="binalar">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="2" class="dataTables_empty">Veriler sunucudan yükleniyor.</td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>

JSON 数据,它有application/json content-type。

{ "aaData" : [ [ "Ersin SEewrZA",
        "eseeza@veritrwqonik.werew"
      ],
      [ "İlhan ŞUBewrAŞI",
        "isuqbasi@veritrewonik.ewrew"
      ]
    ],
  "iTotalDisplayRecords" : 2,
  "iTotalRecords" : 2,
  "sColumns" : "FullName,Email",
  "sEcho" : 0
}

所有文件都正确加载。并且没有 JavaScript 错误。

【问题讨论】:

    标签: jquery datatables


    【解决方案1】:

    您的问题是您没有使用 sEcho 查询参数进行请求,而是在告诉数据表验证参数是否匹配.. 测试一下,如果参数不匹配,它只会处于“处理”中。

    例如:/HCAWebApp/index.php/getbuildings&amp;sEcho=0,因为您在 init 中传递了"sEcho":0

     $('#binalar').dataTable({
        "bProcessing" : true,
        "bServerSide" : true,
        "sAjaxSource" : "/getbuildings.json?sEcho=0"  ,  
        "sEcho": 0
        });
    

    JSFiddle:http://jsfiddle.net/ncapito/VbZhW/4/

    【讨论】:

      【解决方案2】:

      我已将 sAjaxSource 源更改为相对路径并且它有效。 "sAjaxSource" : "../index.php/getbuildings".

      【讨论】:

        猜你喜欢
        • 2021-06-13
        • 2019-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多