Here is the code snippet in question:
// retrieving data via ajax
$.ajax({
'async': false,
'global': false,
'url': url,
'dataType': "json",
'success': function (d) {
data = d;
// code block to define & calculate voteCount
data.votes.totalVotes = voteCount;
localStorage.setItem(url, data);
}
, 'error': function (msg) {
throw new Error("Error while fetching data from " + url);
}
});
If I type data.votes.totalVotes
in the console after the above line:
data.votes.totalVotes = voteCount;
I receive the expected value. However, when I try JSON.stringify(data)
, the property totalVotes
does not appear.
Do you have any insight into why this might be happening, or suggestions for how to resolve it?
** Please note: I have ruled out asynchronous issues as the cause, as the problem persists even within the success callback.