So I'm having issues with the following error:
chartsuccessfulapploginsController.js:59 TypeError: Converting circular structure to JSON at Object.stringify (native)
With this snippet of code, that retrieves data from a chart:
var appjson = '{\"APP_DATA_RETRIEVED\" : \"fail\"}';
var appPostRequest = $.get(appurl, data, appconfig);
appPostRequest.done(function(appdata){
console.log(appdata);
var date=$scope.final.rows[selectedItem.row].c[0].v;
appjson = JSON.stringify(appdata);
console.log(appjson);
var postResponse = jQuery.parseJSON(appjson);
var postResponse2=postResponse.Response;
var post=[];
console.log(postResponse2.length);
for(i=0; i<postResponse2.length; i++){
var data = postResponse2[i];
var dt = new Date(postResponse2[i]['startTime']);
var day = (dt.getMonth() + 1) + '-' + dt.getDate() + '-' + dt.getFullYear();
if(day==date){
post=post.concat(data);
console.log(data);
}
}
console.log(post);
$scope.gridOptions8.data=post;
$scope.failchartvisible=true;
$scope.successchartvisible=false;
console.log($scope.gridOptions8.data);
$scope.$apply()//error originates from here
The "appdata" parameter in the done function is a JSON object that always has this structure:
{
"Response": [{
"challenge": "rp6lssenku72b2ppr4gkjb4q92",
"startTime": "2016-04-26 10:41:46.0",
"successfullyCompleted": false,
"id": 1,
"username": "bojan1037"
}, {
"challenge": "ljtqvmk1mcqqqg5m0op0fljnek",
"startTime": "2016-04-26 10:49:56.0",
"successfullyCompleted": false,
"id": 4,
"username": "bojan1037"
}, {
"challenge": "h062sm69lpkib7t3sk4fuppi1v",
"startTime": "2016-04-26 14:53:31.0",
"successfullyCompleted": false,
"id": 10,
"username": "bojan1037"
}],
"Error": ""
}
I understand that it has something to do with json.stringify. However, I can't for the life of me figure out how to fix the error, as I can't see how that appdata could have a circular reference. Can anyone help me figure it out? Whoever answers correctly will have my eternal gratitude.