dsgk0386 2017-04-19 06:14
浏览 125

无法在DataTable.js jquery插件中的服务器端处理中加载数据

I just started learning DataTable.js and I've got one doubt regarding server-side processing in DataTable.js, that is, how can I load the table in server-side processing?

I'm posting my code here so it would be easy to understand

table.html

<table id="empTable">
  <thead>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Email</th>
    <th>Phone Number</th>
  </thead>
</table>

script.js

<script type="text/javascript">
  var empTable;
  $(document).ready(function(){
    empTable = $("#empTable").dataTable({
      'processing':true,
      'serverside':true,
      'ajax': 'fetchRecord.php'
    });
  });
</script>

fetchRecord.php

<?php
$conn = new mysqli('localhost','root','','example');
if($conn->connect_error) die("Could not connect".$conn->connect_error);

$fetchQuery = "SELECT firstname, lastname, email, phonenumber FROM employee";

$output = array('data' => array());

$result = $conn->query($fetch);
if($result->num_rows > 0){
  while($row = $result->fetch_assco()){
    $output['data'][] = $row;
  }
}

$conn->close();

echo json_encode($output);
?>

Please tell me what's wrong with this code and how can I fetch data from php page and load it in DataTable?

Apologies for any mistakes.

Thank you in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题