2013-02-20 101 views
0

配置數據表我有一個表如下錯誤而使用JSON

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"> 
<thead> 
    <tr> 
     <th>Month</th> 
     <th>ID</th> 
     <th>Comments</th> 
     <th>Details</th> 
    </tr> 
</thead> 
<tbody> 
</tbody> 
</table> 

我的JSON是

[{ 
"Month": "Jan-2013", 
"ID": "asdfa0", 
"Comments": "", 
"Details": "bla bla blba blablabalbal" 
}] 

和我的劇本是

$(document).ready(function() { 
var oTable = $('#example').dataTable({ 
    "bProcessing": true, 
    "sAjaxSource": "Script/ahd.json", 
    "aoColumns": [ 
    { "mData": "Month" }, 
    { "mData": "ID" }, 
    { "mData": "Comments" }, 
    { "mData": "Details" } 
    ] 
}); 
}); 

這樣我收到後以下錯誤

Un抓類型錯誤:無法讀取未定義jquery.dataTables.js的特性「長度」:2649

一點谷歌搜索後,我得到了1個解決方案包裹JSON在

{ 
    aaData: 
    [{ 
"Month": "Jan-2013", 
"ID": "asdfa0", 
"Comments": "", 
"Details": "bla bla blba blablabalbal" 
}] 
} 

這也沒有工作...什麼是錯在這裏

回答

1

閱讀文檔

您的js必須

$(document).ready(function() { 
       $('#example').dataTable({ 
        "bProcessing": true, 
        "bServerSide": true, 
        "sAjaxSource": "Script/ahd.json", 
        "sServerMethod": "POST" 
       }); 
      }); 

和json格式必須是這樣的

{ 
    "sEcho": 3, 
    "iTotalRecords": 6, 
    "iTotalDisplayRecords": 3, 
    "aaData": [ 
    [ 
     "A","B","C" 
    ], 
    [ 
     "A","B","C" 
    ], 
    [ 
     "A","B","C" 
    ], 
    [ 
     "A","B","C" 
    ], 
    [ 
     "A","B","C" 
    ], 
    [ 
     "A","B","C" 
    ], 
    ] 

} 
+0

我如何如何歸檔呢?因爲我有同樣的問題 – Misters 2013-07-06 10:50:36

+0

你能詳細說明你的查詢嗎? – 2013-07-06 10:52:16

+0

與發佈的問題完全相同,即時通訊接收到相同的結果:[{「Name」:「blabla」,「LastName」:「Blabla」},{etc ..},{etc ..}] – Misters 2013-07-06 10:54:57