๐:0
You are returning Response(data)
. I have no idea what type of Response this is. Better return a JsonResponse.
from django.http import JsonReponse
class ChartData(APIView):
# your code
def get(self, request, format=None):
# your code
return JsonResponse(data)
Then in your js script, specify the dataType as json
, or parse the data explicitly.
// Specify the dataType as json
$.ajax({
method: "GET",
urls: endpoint,
dataType: "json",
// rest of your code
});
// Explicitly parse data
$.ajax({
success: function(data){
jsonData = JSON.parse(data);
labels = jsonData.labels;
defaultData = jsonData.default;
setChart();
},
// rest of your code
});