In my django app the datatable makes a ajax REST api request where the response is as follows:
{
"data": ["some content here"],
"time_data": [
{
"Last_updated": "Jan 07 2020 06: 09 CST",
"Next_scheduled": "Jan 07 2020 07: 09 CST"
}
]
}
This is the django REST API view is as follows:
class clustersView(views.APIView):
def get(self, request):
results = {}
clusters = get_collection('clusters')
results['data'] = ClusterSerializer(clusters, many=True).data
results['time_data'] = get_collection('time_data')
return Response(results)
In the above response json the data
key has been accessed as follows and used to populate the datatable and it works fine.
$(document).ready(function () {
myTable = $('#table').DataTable({
ajax: {
"type": "GET",
"url": "{% url 'Clusters' %}",
},
columns: [
{ 'data': 'Master' },
{ 'data': 'Workers' },
{ 'data': 'Build' },
{ 'data': 'Team' }]
});
});
But the next key i.e, time_data
needs to be used in a div which is outside the datatable.
How can i access the response contents in javascript? So that i can use time_data
from the response.
Note: accessing the django response variable results
, throws a error that the variable is not defined.