Data object not displaying data in my table
Data object not displaying data in my table
Genesis
Posts: 1Questions: 1Answers: 0
Hi Peeps
Completely noooob at this but if anyone can assist me i would highly appreciate it. I have tried various threads to and nothing is working. Please HELP... If you have any suggestions of how ever else i can do it, please state so, working on a REST API thats needs authentication sent as well.
Example of my json object (Its rather a huge source so im cutting it short just to give you an idea of what im working with):
{
objects: [
{
id: "2717eb66-95d3-11e6-860e-001e67260782",
type: "alert",
updated_at: "2016-10-19T08:08:21Z",
display: "You Win",
sighting_id: "26341|1476864434252|1",
source_system_id: "CLE",
alert_id: "27d0992dfba243cab09ebfa18503b89e",
timestamp: "2016-10-19T08:07:16Z",
time_string: "10:07",
alert_type_id: {
key: 2,
display: "Winner"
}.........
here is my Javascript:
var xhr = new XMLHttpRequest();
xhr.open("GET", api_url, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Authorization", 'Basic '+btoa(username+':'+password));
xhr.onload = function() {
var obj = jQuery.parseJSON(xhr.responseText);
$('#maintable').dataTable({
"processing": true,
"aaData": obj,
"aoColumns": [
{ "mData": "objects.id" },
{ "mData": "objects.type" },
{ "mData": "objects.updated_at" },
{ "mData": "objects.display"},
{ "mData": "objects.timestamp"}
]
});
};
xhr.send();
My Html:
<div class="container">
<table id="maintable" class="table table-striped table-condensed">
<thead>
<tr>
<th>id</th>
<th>type</th>
<th>updated_at</th>
<th>display</th>
<th>timestamp</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
<th>type</th>
<th>updated_at</th>
<th>display</th>
<th>timestamp</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
</div>
This discussion has been closed.