我检查了Firefox中的网络监视器,并说我成功获取了Json数据。在春季指南中,应该是:
{
"id": 37658,
"content": "Hello, World!"
}
但是我的数据表上有no data available in table
。我想念什么吗?
位于Plunker的完整代码
表格:
<table id="example" class="display" style="width: 100%">
<thead>
<tr>
</tr>
</thead>
</table>
脚本:
<script>
$(document).ready(function() {
$('#example').DataTable({
"ajax" : {
"dataType" : 'json',
"contentType" : "application/json; charset=utf-8",
"url" : "http://rest-service.guides.spring.io/greeting",
"dataSrc" : "",
},
columns: [{
data: "id",
name: "id",
title: "Id"
},
{
data: "content",
name: "content",
title: "content"
}]
});
});
</script>
答案 0 :(得分:0)
我的列语法不正确。其固定如下,并添加了一些参数:
<script>
$(document).ready(function() {
$('#example').DataTable({
"ajax" : {
"dataType" : 'json',
"contentType" : "application/json; charset=utf-8",
"url" : "http://rest-service.guides.spring.io/greeting",
"dataSrc" : "",
},
"columns": [
{ "data": "id"},
{ "data": "content"}
]
});
});
</script>