JSON Object XHR and closures
- by Sara Chipps
Hi all, I have a JSON object that is populated by an XHR. I then need to update that object with values from a separate XHR call. The issue I am running into is the second call isn't being made at the correct time and I think it's an issue with how I structured my object. Here is what I have:
function Proprietary()
{
var proprietary= this;
this.Groups = {};
this.getGroups = function()
{
$.getJSON(group_url, function(data){proprietary.callReturned(data);});
}
this.callReturned = function(data)
{
//Do stuff
for(var i=0; i< data.groups.length; i++)
{
insparq.Groups[i] = data.groups[i];
$.getJSON(participant_url, function(p){proprietary.Groups[i].participants = p;});
}
//the function call below is the action I want to occur after the object is populated.
PopulateGroups();
}
};