2016-04-22 164 views
1

嘿所有我有以下的JSON從Web服務使用AJAX來:datatables.net數據未顯示錯誤TN/4

{ 
"data": [ 
    [ 
    "11/11/2014 3:02:37 PM", 
    "4/13/2015 8:26:37 AM", 
    "032650147", 
    "NULL", 
    "Web Site Problems", 
    "NULL", 
    "New", 
    "6230.758742407" 
    ], 
    [ 
    ...etc etc.... 
    ] 
] 
} 

而且我動態創建HTML表所示:

<table id="example" class="display" cellspacing="0" width="100%"> 
    <thead> 
    <tr> 
     <th>Contact Date Time</th> 
     <th>Last Update Date Time</th> 
     <th>Member ID</th> 
     <th>Operator NTID</th> 
     <th>Question</th> 
     <th>Redirect Email Address</th> 
     <th>Status</th> 
     <th>Receipt Date</th> 
     </tr> 
    </thead> 
</table> 

而且使用JavasScript,我使用,以顯示在表中返回的數據是:

$.ajax({ 
    type: "POST", 
    crossDomain: true, 
    url: "complete.aspx/getMemberEmailsDBData", 
    beforeSend: function (xhrObj) { 
     xhrObj.setRequestHeader("Content-Type", "application/json"); 
    }, 
    data: {}, 
    dataType: "json", 
    success: function (data) { 
     console.log(data.d); 
     $('#example').DataTable({ 
      data: data.d, 
      columns: [ 
       { title: "ContactDateTime" }, 
       { title: "LastUpdateDateTime" }, 
       { title: "MemberID" }, 
       { title: "OperatorNTID" }, 
       { title: "QuestionArea" }, 
       { title: "RedirectEmailAddress" }, 
       { title: "Status" }, 
       { title: "ReceiptDate" } 
      ] 
     }); 
    }, 
    error: function (XMLHttpRequest, textStatus, errorThrown) { 
     console.log(XMLHttpRequest); 
    } 
}); 

加載頁面後,它不斷給我警報彈出,告訴我說:

數據表警告:表ID =例子 - 請未知參數「1」 爲行0,列1。有關更多信息,此錯誤請參閱 http://datatables.net/tn/4

任何人看到我失蹤以解決這個問題?

+0

什麼'的console.log(data.d); '輸出? – davidkonrad

+0

我在上面的OP中發佈的JSON。 – StealthRT

回答

1

使用

data: data.d.data, 

當您使用javascript array source,數據表不想到裹成data : [ ... ]來源,而只是一個數組的數組。

你的代碼在一個小演示 - >http://jsfiddle.net/jusbngww/

+0

沒有錯誤,但沒有數據顯示在表中... – StealthRT

+0

如果你嘗試'console.log(data.d.data)'它輸出一個'array [x]'?您肯定應該在此時形成良好的JSON。 – davidkonrad

+0

當使用** console.log(data.d.data)時,我得到一個** undefined ** ** – StealthRT