我正在尝试将 JSON 数据放入我的数据表中,但不知何故它不起作用。请帮助我,
<script>
$.getJSON('../vendor/process/process_vendor.php', function(response) {
$('#vendorlist').DataTable({
processing: true,
data: response.data,
columns: [
{ data: "PO_NO"}
]
});
window.someGlobalOrWhatever = response.balance;
});
</script>
这是 process_vendor.php
$sql = oci_parse($conn, "SELECT VPI.PO_NO FROM VW_PO_INFO@WENFINANCE_WENLOGINV_LINK VPI WHERE VPI.PROJECT_NO LIKE '%' AND VPI.PROJECT_NAME LIKE '%'");
$errExc = oci_execute($sql);
if (!$errExc){
$e = oci_error($sql);
print htmlentities($e['message']);
print "\n<pre>\n";
print htmlentities($e['sqltext']);
printf("\n%".($e['offset']+1)."s", "^");
print "\n</pre>\n";
} else {
$res = array();
while ($row = oci_fetch_assoc($sql)){
$res[] = $row;
}
$listPO = json_encode($res, JSON_PRETTY_PRINT);
print_r($listPO);
oci_free_statement($sql); // FREE THE STATEMENT
oci_close($conn); // CLOSE CONNECTION, NEED TO REOPEN
}
和 JSON 数据:
[
{ "PO_NO": "0928-57\/WEN\/15" },
{ "PO_NO": "0928-57\/WEN\/15" },
{ "PO_NO": "0923-59\/WEN\/15" },
{ "PO_NO": "0916-57\/WEN\/15" },
{ "PO_NO": "1002-06\/WEN\/15" }
]
最佳答案
由于您的响应中没有关键数据
,请尝试使用:do console.log(response)
检查您是否已正确收到数据。
var responseObj = JSON.parse(response);
然后使用 responseObj
获取数据。
data: responseObj,
原始数据示例:
var response=[ { "PO_NO": "0928-57/WEN/15" }, { "PO_NO": "0928-57/WEN/15" }, { "PO_NO": "0923-59/WEN/15" }, { "PO_NO": "0916-57/WEN/15" }, { "PO_NO": "1002-06/WEN/15" }];
$('#vendorlist').DataTable({
processing: true,
data: response,
columns: [
{ data: "PO_NO"}
]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
<table id="vendorlist"></table>
关于javascript - 将 JSON 数据从 ORACLE 获取到 Jquery Datatables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33232308/