数据表从第0行的数据源请求未知参数“0”

时间:2017-12-12 16:04:26

标签: php json datatables

这是我的json响应代码示例:

[{"data":"{\"time\": \"2017-12-12 11:17:48\", \"user\": \"firman\", \"owner\": \"admin\", \"host_ip\": \"127.0.0.1\", \"user_ip\": \"192.168.3.235\", \"nas_port\": \"2162163717\", \"log_status\": \"accounting-success\", \"nas_port_id\": \"ether3-Hotspot\", \"nas_port_type\": \"wireless-802.11\", \"calling_station_id\": \"58:44:98:A0:A4:88\"}"},{"data":"{\"time\": \"2017-12-12 11:57:07\", \"user\": \"lenovo\", \"owner\": \"admin\", \"host_ip\": \"127.0.0.1\", \"user_ip\": \"192.168.3.236\", \"nas_port\": \"2162163713\", \"log_status\": \"accounting-success\", \"nas_port_id\": \"ether3-Hotspot\", \"nas_port_type\": \"wireless-802.11\", \"calling_station_id\": \"64:DB:43:BB:52:CF\"}"},{"data":"{\"time\": \"2017-12-12 04:59:19\", \"user\": \"endigo\", \"owner\": \"admin\", \"host_ip\": \"127.0.0.1\", \"user_ip\": \"192.168.3.240\", \"nas_port\": \"2160066562\", \"log_status\": \"accounting-success\", \"nas_port_id\": \"ether3-Hotspot\", \"nas_port_type\": \"wireless-802.11\", \"calling_station_id\": \"02:40:20:8F:F7:C0\"}"}]

当我加载页面时,从第0行show

的数据源请求未知参数'0'

这是我的数据表代码:

<script type="text/javascript">
$("#radius_log").DataTable({
fixedColumns: true,
fixedHeader: true,
"pageLength": 10,
"paging": true,
"ajax": {
    url: "./all_log",
    type: "GET",
    dataSrc: ""
},
"scrollX": true,
"columns": [
    {"data": "owner", "title": "Owner"},
    {"data": "user", "title": "User"},
    {"data": "user_ip", "title": "IP Address"},
    {"data": "host_ip", "title": "Radius Server"},
    {"data": "nas_port_id", "title": "NAS Port"},
    {"data": "nas_port_type", "title": "NAS Port Type"},
    {"data": "time", "title": "Time"}
    ]
     });
    </script>

2 个答案:

答案 0 :(得分:1)

您的JSON返回的是:

enter image description here

你想要的是:

enter image description here

答案 1 :(得分:0)

有了小提琴会让它更容易,所以这里有一个:https://jsfiddle.net/g5fa1mo0/

我实际上收到了2条错误消息,第二条非常明确,并指出第一条记录中缺少owner