I'm trying to display the REST call JSON response in jQuery datatables.
Below is the JSON response I'm receiving.
{
"artifact": [
{
"artifactId": "I8cc4a96ef69a11e08b448cf533780ea2",
"batchId": "15581",
"processId": "115458787"
},
{
"artifactId": "e08b448cf533780ea2I8cc4a96ef69a11",
"batchId": "14962",
"processId": "787974254"
}
]
}
The Script:
<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>
The 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>
Can someone provide an answer on why I am unable to load the JSON response into datatable? Is there a better approach to get this functionality?