我的ajax呼叫是:
var networkslisttab = null;
...
networkslisttab = $('#networkslisttable').DataTable({
"ajax": { "url": networkstoolboxURL, "dataType": "json", "dataSrc": '', "success": function (data) { networkslisttab.processing(false); console.log(data); }, "error": function (error) { console.log("error in networks"); } },
//"dataSrc": '',
"columns": [
{
"data": 'reference_id',
"width": '15%',
},
{ "data": 'name' },
{
"data": 'num_points',
"width": '15%',
},
{
"data": 'num_sections',
"width": '15%',
}
],
"order": [[0, "desc"]],
"processing": true,
"autoWidth": false, // need this to handle rendering issues in bootstrap and during re-size. Note handlers at end of page.
"scrollY": "200px", // make it a small scrolling table
"scrollX": true,
"paging": false,
"info": false,
"language": {
"processing": '<span style="width:100%;"><img src="/Content/icons/ajax-loader-orange-med.gif" /></span>'
},
"searching": false
});
“成功”中的 console.log 給了我以下 json 陣列,但它沒有系結到資料表
[{reference_id: '873', name: 'MapTest', details: 'Sourced from Open Street Maps', num_points: 0, num_sections: 23}, {reference_id: '899', name: 'Albury C road', details: '來源于 Open Street Maps',num_points: 0, num_sections: 0}]
但它沒有系結到桌子上我錯過了什么?
更新
通過洗掉成功和錯誤屬性,資料開始系結..為什么?
networkslisttab = $('#networkslisttable').DataTable({
"ajax": {
"url": networkstoolboxURL,
"dataSrc": ''
}
"columns": [
{
"data": 'reference_id',
"width": '15%',
},
{ "data": 'name' },
{
"data": 'num_points',
"width": '15%',
},
{
"data": 'num_sections',
"width": '15%',
}
],
"order": [[0, "desc"]],
"processing": true,
"autoWidth": false, // need this to handle rendering issues in bootstrap and during re-size. Note handlers at end of page.
"scrollY": "200px", // make it a small scrolling table
"scrollX": true,
"paging": false,
"info": false,
"language": {
"processing": '<span style="width:100%;"><img src="/Content/icons/ajax-loader-orange-med.gif" /></span>'
},
"searching": false
});

uj5u.com熱心網友回復:
如您所見,您不應該success在 DataTables選項中覆寫 jQuery Ajaxajax選項。
如此處所述:
...不應該更改的
success選項- DataTables 在資料加載完成時在內部使用它來執行表格繪制。ajax
請改用該dataSrc選項,以便在通過 Ajax 接收 JSON 回應后進行任何自定義處理。
(我沒有嘗試error過 DataTablesajax選項的屬性 - 它可能與該success選項的情況相同。我鏈接到的檔案中沒有提到。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/492036.html
