所以,这里是我的AJAX调用的数据表的表对象。 我试图让JSON填写只有行的表,因为它已经有标题行。
我并不清楚什么数据表Ajax调用,因为它们之间的区别从一个版本到其他的语法。
$('#MainContentPlaceHolder_business_return_flights').dataTable({
"ajax": {
"url": "Browse.aspx/GetBusinessFlights",
"type": "POST",
"contentType": "application/json; charset=utf-8",
"dataType": "json"
}
});
我不断收到错误: Uncaught TypeError: Cannot read property 'length' of undefined
这里是返回的JSON:
{
"d":{
"draw":"1",
"recordsTotal":"70",
"recordsFiltered":"70",
"aData":[
[
"BI 098",
"London (LHR)",
"Dubai",
"08-08-2014",
"12:55 PM",
"11:55 PM",
"Royal Brunei",
"1",
"0",
"1300",
"\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectFlight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003eBook\u003c/button\u003e"
],
[
"CY 383",
"Dubai",
"Larnaca",
"08-06-2014",
"1:45 PM",
"4:05 PM",
"Cyprus Airways",
"1",
"0",
"1100",
"\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectFlight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003eBook\u003c/button\u003e"
]
]
}
}
更新:这是我回报的方法:
[WebMethod]
public static Dictionary<string, object> GetBusinessFlights()
{
listRows = new List<List<string>>();
business = new Table();
economy = new Table();
FillTable(economy, business, scheduledFlights.List);
foreach (TableRow row in business.Rows)
{
listRow = new List<string>();
foreach (TableCell cell in row.Cells)
{
listRow.Add(cell.Text);
}
listRows.Add(listRow);
}
field = new Dictionary<string, object>() { { "draw", "1" }, { "recordsTotal", economy.Rows.Count.ToString() }, { "recordsFiltered", economy.Rows.Count.ToString() }, { "aData", listRows } };
return field;
}
注: FillTable()
只填充数据到商业和经济表对象。