【发布时间】:2012-03-23 17:01:16
【问题描述】:
我正在尝试在 jQuery datatables 中显示 REST 调用 JSON 响应。
以下是我收到的 JSON 响应。
{
"artifact": [
{
"artifactId": "I8cc4a96ef69a11e08b448cf533780ea2",
"batchId": "15581",
"processId": "115458787"
},
{
"artifactId": "e08b448cf533780ea2I8cc4a96ef69a11",
"batchId": "14962",
"processId": "787974254"
}
]
}
脚本:
<script type="text/javascript">
$(document).ready(function () {
$("#artifacts").dataTable({
"sPaginationType": "full_numbers",
"bJQueryUI": true
});
});
function submitForm()
{
$.getJSON('http://myurl.com/JerseySample/rest/search', function(data) {
$.each(data.artifact, function(i,artifact){
$('#artifacts').datatable().fnAddData([
artifact.artifactId,
artifact.batchId,
artifact.processId ]
);
});
});
}
</script>
HTML:
<form class="searchform">
<input class="searchfield" type="text" />
<input class="searchbutton" type="button" value="Go" id="go" onclick="submitForm()" />
</form>
<div id="container">
<div id="demo_jui">
<table id="artifacts" class="display">
<thead>
<tr>
<th>Artifact Id</th>
<th>Batch Id</th>
<th>Legacy Id</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
有人可以回答为什么我无法将 JSON 响应加载到数据表中吗?有没有更好的方法来获得这个功能?
【问题讨论】:
标签: jquery jquery-plugins datatables