【问题标题】:How to display these data in data table with ajax?如何用ajax在数据表中显示这些数据?
【发布时间】:2018-03-07 12:23:36
【问题描述】:

我在建议的问题中没有问题。

{
  "aaData": [
    {
      "id": "1",
      "reg_d": "2017-09-15 10:15:57",
      "fname": "Vishwas",
      "lname": "Jadav",
      "email": "vjadav@live.com"
    },
    {
      "id": "50",
      "reg_d": "2017-09-20 14:33:59",
      "fname": "testA",
      "lname": "testk",
      "email": "test5@gmail.com"
    },
    {
      "id": "51",
      "reg_d": "2017-09-20 14:36:18",
      "fname": "mvjh",
      "lname": "kgjk",
      "email": "teesth@jhk.com"
    }
  ],
  "draw": 5,
  "recordsTotal": 35,
  "recordsFiltered": 5
}

我使用的代码是:

<script type="text/javascript">
    $(document).ready(function() {
    $("#table1").dataTable({
      "preocessing" : true,
      "serverSide" : true,
      "sAjaxSource" : "dtable2.php",
      "columns" : [
        {"data" : "aaData.1"},
        {"data" : "aaData.3"},
        {"data" : "aaData.4"},
        {"data" : "aaData.5"},
        {"data" : "aaData.2"},
      ]
    });
    });
  </script>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">

  </head>
  <body>
    <table id="table1">
      <thead>
        <tr>
          <th>Id</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Email</th>
          <th>Date</th>
        </tr>
      </thead>
    </table>
  </body>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
  
</html>

但我在结果中收到警告

"DataTables 警告 (table id = 'table1'): 请求的未知参数 第 0 行的数据源中的“0”

我在建议的问题中没有问题。

【问题讨论】:

标签: javascript php ajax datatables


【解决方案1】:

你试试这个代码:

<script type="text/javascript">
$(document).ready(function() {
$("#table1").dataTable({
  "preocessing" : true,
  "serverSide" : true,
  "sAjaxSource" : "dtable2.php",
  "columns" : [
    {"data" : "id"},
    {"data" : "fname"},
    {"data" : "lname"},
    {"data" : "email"},
    {"data" : "reg_d"},
  ]
});
});

查看更多:Columns render

【讨论】:

  • 谢谢 我感觉自己很笨,很简单。非常感谢
【解决方案2】:

您没有在此处向插件提交正确形式的数据,

"columns" : [
        {"data" : "aaData.1"},
        {"data" : "aaData.3"},
        {"data" : "aaData.4"},
        {"data" : "aaData.5"},
        {"data" : "aaData.2"},
      ]

例如:aaData.1 无法被插件读取。

Check here too

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多