help with loading table via ajax/json data
help with loading table via ajax/json data
Hello i was wondering if someone could help me understand how to load my data table.
The data i am getting is via jquery ajax call and coming back in json format.
The trick is i have two objects in the json result. One of those objects has two tables. So how to refer to these columns is proving difficult for me to understand.
Here is my html for the table.
<table id="meetingdata">
<thead>
<tr>
<th>Date</th>
<th>Meeting Type</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Here is my jquery ajax call. As you can see there is an attempt to load json into the meetingdata datatable but i cannot get it to load. Also It would be best if i could get meetingtype and meetindate field from both of the objects.
(novusdata.dtmeetings.meetingtype and azuredata.document.sysmtgtype) JSON Data is at bottom of this post.
$.ajax({
type: "GET",
url: theUrl,
contentType: "application/json",
dataType: "json",
success: function (data) {
data = JSON.parse(data);
$('#meetingdata').dataTable({
"ajaxSource": data,
"columns": [
{ "data": "NovusData.dtMeetings.MeetingDate" },
{ "data": "NovusData.dtMeetings.MeetingType" },
]
});
},
error: function (jqxhr, textStatus, e) {
alert("Error (jqxhr): " + jqxhr.responseText);
alert("Error Status: " + textStatus);
alert("Error (e): " + e);
}
});
Here is what the returned json looks like.
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
{"NovusData":{"dtItems":[{"MeetingID":460,"AgendaItemID":3586,"MeetingDate":"2018-01-30T12:30:00","Title":"Amd 2 to Agmt A111471 with BFI for ash disposal from HERC at Sarona Landfill","AgendaCategory":"Routine Items","MeetingType":"Public Works Committee","Location":"Government Center - County Board Chambers","MinutesMeetingID":1228},{"MeetingID":435,"AgendaItemID":3552,"MeetingDate":"2018-01-23T12:30:00","Title":"Amd 2 to Agmt A111471 with BFI for ash disposal from HERC at Sarona Landfill","AgendaCategory":"Referred to Public Works Committee","MeetingType":"Board Meeting","Location":"Government Center - County Board Chambers","MinutesMeetingID":1212}],
"dtMeetings":[{"MeetingID":460,"MeetingDate":"2018-01-30T12:30:00","MeetingType":"Public Works Committee","MeetingTypeID":2,"Location":"Government Center - County Board Chambers","MinutesMeetingID":1228},{"MeetingID":435,"MeetingDate":"2018-01-23T12:30:00","MeetingType":"Board Meeting","MeetingTypeID":1,"Location":"Government Center - County Board Chambers","MinutesMeetingID":1212}]}
,"AzureData":[{"Score":0.014304757,"Highlights":null,"Document":{"id":null,"mtgtype":null,"doctype":null,"filename":"309008.pdf","sysmtgtype":"Heath Committee","mtgdate":"2018-03-08T00:00:00Z","content":null}},{"Score":0.010430552,"Highlights":null,"Document":{"id":null,"mtgtype":null,"doctype":null,"filename":"309174.pdf","sysmtgtype":"Operations Committee","mtgdate":"2018-05-04T00:00:00Z","content":null}},{"Score":0.009884065,"Highlights":null,"Document":{"id":null,"mtgtype":null,"doctype":null,"filename":"373132.pdf","sysmtgtype":"County Administration Committee","mtgdate":"2018-03-04T00:00:00Z","content":null}}]}]}
</string>
Hope someone can help
This question has an accepted answers - jump to answer
Answers
Hi @shougom ,
First things, that Json is badly formed - run it through a parser and you'll see there's too many closing brackets on the end.
Then, if you do something like this, that should do the trick,
Cheers,
Colin