使用AJAX插入数据,但数据表未显示任何结果

时间:2019-06-17 16:18:53

标签: php json ajax twitter-bootstrap

我想使用AJAX从数据库加载数据并使用DataTable显示它。数据库已加载并且可以看到,但是数据表显示:

显示0个条目中的0到0(从NaN个总条目中过滤)

 <table id="employee_data" class="table table-striped table-bordered">
             <thead>
             <tr>
                 <td>ID</td>
                 <td>Name</td>
                 <td>Department</td>
                 <td>Job Title</td>
                 <td>Employee Type</td>
                 <td>Employee Status</td>
             </tr>
             </thead>

         </table>


 <script type="text/javascript" language="javascript">
     $(document).ready(function(){
         $('#employee_data').DataTable({
             "processing" : true,
             "serverSide" : true,
             "order" : [],
             "searching" : true,
             "ajax" : {
                 url: 'employeeData.php',
                 type: "post",
                 dataType: "json",
                 contentType: "application/json; charset=utf-8"
             },
             "columns": [
                 { "data": "eId"},
                 { "data": "eName"},
                 { "data": "eDepartment"},
                 { "data": "eJobTitle"},
                 { "data": "eEmployeeType"},
                 { "data": "eEmployeeStatus"}
             ]
         } );

     });
 </script>

employeeData.php

 $query ="
 SELECT *
 FROM employee
 ORDER BY employeeID DESC";
 $result = mysqli_query($link, $query);

 $data = array();

 while($row=mysqli_fetch_array($result))
 {
     $data['data'][] = array(
         'eId'  => $row['employeeId'],
         'eName'  => $row['employeeLastName'],
         'eDepartment' => $row['department'],
         'eJobTitle'  => $row['jobTitle'],
         'eEmployeeType'  => $row['employeeType'],
         'eEmployeeStatus'  => $row['employeeStatus']

     );

 }

 echo json_encode($data);

enter image description here

0 个答案:

没有答案