无法显示使用与源数据表作为JSON字符串数据

问题描述:

我的jQuery代码:无法显示使用与源数据表作为JSON字符串数据

$('#tableid').dataTable({ 
      "processing": true, 
      "serverSide": true, 
      "ajax": { 
         "url": url, ---> My call to servlet 
         "type": "POST", 
        "columns": [ 
         { "sTitle": "FName" }, 
         { "sTitle": "Mname" }, 
         { "sTitle": "LName" }, 
        ] 
        } 
       }); 

我从后端来JSON字符串是:

[{"Fname":"abc","Mname":"ezc","Lname":"JSH"}] 

我的HTML页面:

<table id="tableid" class="display"> 
    <thead> 
     <tr> 
      <th>FName</th> 
       <th>Mname</th> 
       <th>Lname</th> 
     </tr> 
    </thead> 
</table> 

我不知道我在这里错过了什么。没有验证错误。结果没有显示在页面上。

+0

我想你的JSON值需要被称为'data':[https://datatables.net/reference/option/ajax#Types](https://datatables.net/reference/option/ajax #Types广告) – markpsmith 2015-02-09 14:15:03

Got this running. 

Jquery code to be used: 
var posting = $.post(url); 
       posting.done(function(data) { 
        $('#tableid').dataTable({ 
         "aaData": data, 
         "columns": [ 
          { "data": "Fname" }, 
          { "data": "Mname" }, 
          { "data": "Lname" } 
          ] 
        }); 

     }); 

Added 
<td> tags in html for respective fields. 

Will be useful to those who want to fetch the data from backend in json string and display in datatable.