无法在jquery中获取数据表中的数据

时间:2017-09-22 09:32:39

标签: javascript php jquery

服务器端: 这是我获取数据(行)的代码。

<?php
          include 'config.php';
          $sql = "SELECT * FROM users WHERE id BETWEEN '1' and '5'";
          $result = mysqli_query($conn,$sql);
          $counts = mysqli_num_rows($result);

          $res = array('sEcho' => 5 ,
                       'iTotalRecords' => $counts,
                       'iTotalDisplayRecords' => 5,
                       'aaData' => array(),
                     );
          while ($row = mysqli_fetch_assoc($result))
          {
                $res['aaData'][] = $row;
          }
          header('Content-Type: application/json');
          echo json_encode($res);
 ?>

在这里,我试图制作数据表,但

  $(document).ready(function() {
        $.ajax({
                  type : 'POST',
                  url : 'dtable1.php',
                  data : '',
                  success : function(data)
                  {
                      $("#dtable1").dataTable({
                        "bProcessing" : true,
                        "sAjaxSource" : "dtable1.php",
                        "bServerSide" : true,
                        "sAjaxDataProp": "aaData",
                        "aoColumns" : [
                                      { aaData : "id"},
                                      { aaData : "fname"},
                                      { aaData : "lname"},
                                      { aaData : "email"},
                                      { aaData : "reg_d"},
                                    ]
                      });
                  }
                })
      });

JSON结果(数据):

{
"sEcho":5,
"iTotalRecords":4,
"iTotalDisplayRecords":5, 
"aaData":[
          {
            "id":"1",
           "reg_d":"2017-09-1510:15:57",
            "fname":"Vishwas",
            "lname":"Jadav",
            "email":"vjadav@live.com"
          },
          {
            "id":"2",
            "reg_d":"2017-09-14 16:07:05",
            "fname":"Krishna",
            "lname":"Jadav",
            "email":"kjadav@outlook.com"
           },
           {
             "id":"3",
             "reg_d":"2017-09-1416:08:34",
             "fname":"Ashok",
             "lname":"Sadhu",
             "email":"asadhu@gmail.com"
            },
            {
             "id":"4", 
             "reg_d":"2017-09-1418:33:11",
             "fname":"Ashok",
             "lname":"Sadhu",
             "email":"asadhu@hmail.com"
            }
          ]
}

0 个答案:

没有答案