无法使用带有源为JSON字符串的数据表显示数据

时间:2015-02-09 13:44:49

标签: jquery json jquery-datatables

我的Jquery代码:

$('#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>

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

1 个答案:

答案 0 :(得分:0)

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.