我需要从AJAX源加载数据表。我的PHP脚本以这种形式返回JSON输出:
{
"SiteID": "61",
"SiteRef": "MI Swaco, Pocra Quay (Elect 910)",
"SupplierID": "1",
"StartDate": "2013-06-01 00:00:00.000",
"EndDate": "2014-05-31 00:00:00.000",
"Voltage": "LV"
},
{
"SiteID": "8",
"SiteRef": "UK Training Centre, (Elect 318)",
"SupplierID": "1",
"StartDate": "2013-07-01 00:00:00.000",
"EndDate": "2014-06-30 00:00:00.000",
"Voltage": "LV"
},
{
"SiteID": "115",
"SiteRef": "Smith Int, Bruce Fac (Gas 102)",
"SupplierID": "31",
"StartDate": "2013-08-01 00:00:00.000",
"EndDate": "2014-07-30 00:00:00.000",
"Voltage": "LV"
}
我已通过JSONLint对其进行了验证,并表示它是一个有效的JSON输出。但是,当我将它用于数据表时,它表示无效的json输出。这就是我将它与dataTable接口的方式:
$(function() {
//$('#termTable').dataTable().makeEditable();
$('#termTable').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "terminateContractList.php"
},
"columns": [
{"data": "SiteID"},
{"data": "SiteRef"},
{"data": "SupplierID"},
{"data": "StartDate"},
{"data": "EndDate"},
{"data": "Volatage"}
]
});
});
答案 0 :(得分:3)
请更正代码中的电压拼写。
$( function(){
//$('#termTable').dataTable().makeEditable();
$('#termTable').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "terminateContractList.php"
},
"columns": [
{ "data": "SiteID" },
{ "data": "SiteRef" },
{ "data": "SupplierID" },
{ "data": "StartDate" },
{ "data": "EndDate" },
{ "data": "Voltage" }
]
} );
});
JSON数据中的“电压”与dataTable中的“Volatage”列不匹配