有 PHP 经验,但对 jQuery 不熟悉:我想用 ajax 从 json 编码的 php 文件中获取数据来填充一个简单的数据表。
table.php
: HTML 片段
<head>...
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": 'deliver_tests.php',
"sScrollY": "200px",
"bPaginate": false
});
} );
</script>
</head>
<body> ...
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
<thead>
<tr>
<th>id</th>
<th>Status</th>
<th>Abkürzung</th>
<th>Test</th>
<th>Patient</th>
<th>Datum</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
deliver_tests.php
:代码片段:
try {
$sql = "SELECT tsID, tsStatus, tbShortname, tbName, paCode, tsCompleted_Date FROM test LEFT JOIN testbase ON tsTestBaseID = tbID LEFT JOIN patient ON tsPatientID = paID WHERE tsAccountID=:accID ORDER BY tsCompleted_Date DESC";
$dbTests = $objDB->prepare($sql);
$bind=array('accID' => $_SESSION['aID']);
$dbTests->execute($bind);
$tests = $dbTests->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $dbe) {
// error
}
$tests = array('aaData' => $tests);
echo json_encode($tests);
在此处查看其输出:http : //pastebin.com/uZiLepSb
调用table.php
,我得到一个js-alert:
DataTables warning (table id = 'example'):
Requested unknown parameter '0' from the data source for row 0
我想我必须重新组合那个数组?
我需要关于如何从这里继续的提示 - 提前谢谢你!