将ORACLE中的JSON数据导入Jquery数据表

时间:2015-10-20 09:00:32

标签: javascript php json oracle

我正在尝试将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 DATA:

[
  { "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" }
]

1 个答案:

答案 0 :(得分:2)

由于您的回复中没有密钥data,请尝试使用:执行console.log(response)检查您是否已正确接收数据。

 var responseObj = JSON.parse(response);

然后使用responseObj获取数据。

data: responseObj,

原始数据示例:

&#13;
&#13;
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"}
          ]
        });
&#13;
<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>
  
  
&#13;
&#13;
&#13;