【发布时间】:2018-01-23 14:51:38
【问题描述】:
我的问题是 Jquery DataTables 在加载时挂起,不会显示来自 php 脚本的任何数据:
这是我的 HTML:
<!-- Default box -->
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Time Management</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<table id="example" class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Clock In</th>
<th>Lunch Started</th>
<th>Lunch Ended</th>
<th>Clock Out</th>
</tr>
</thead>
</table>
</div>
<!-- /.box-body -->
<div class="box-footer">
Footer
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
我的 Jquery 代码:
<script>
$(document).ready(function() {
$('#example').DataTable({
"ajax": "api/timemanageprocess.php",
"dataSrc": '',
"type": "POST",
"columns": [
{"data": "PASS_ID"},
{"data": "CLOCK_IN"},
{"data": "START_LUNCH"},
{"data": "END_LUNCH"},
{"data": "CLOCK_OUT"}
],
});
});
</script>
还有我的 PHP 脚本的结果。我回应了 json_encode() 的结果:
我尝试使用"data": data & "data": json 作为DataTable() 中的选项。我试图用大括号来定义 ajax 的选项。我试过完全排除dataSrc='',我试过删除type: 'POST'并将其留给GET。我知道我的 php 脚本地址是正确的。我不知道是什么或它们阻止了数据填充到数据表中。有人可以帮我弄清楚吗?提前致谢。非常感谢您的帮助。
PHP
include ('../includes/sessions.php');
$select = "SELECT PASS_ID, CLOCK_IN, START_LUNCH, END_LUNCH, CLOCK_OUT FROM timeclock WHERE USERNAME = '$sessuser'";
$query = mysqli_query($dbc, $select) or die(mysqli_error($dbc));
$resnum = mysqli_num_rows($query);
//echo $resnum;
while($row = $query->fetch_assoc())
{
$out[] = $row;
}
echo json_encode(array('data' => $out));
mysqli_free_result($query);
$dbc->close();
?>
【问题讨论】:
-
所以这是一个帖子而不是一个获取?这行得通吗? ajax: { "url": 'api/timemanageprocess.php', "type": "GET", "dataSrc": ''}
-
@BryanDellinger 不幸的是,没有。
-
所以你确实看到你有 "ajax": "api/blahblahblah",当我认为它应该是 ajax:{url: yoururl, type: 'POST', dataSrc: ''} 时,你剩下的东西
-
@BryanDellinger 我过去尝试过,遗憾的是数据没有填充到表格中。
标签: php jquery ajax datatable datatables