JSON Object XHR and closures

Posted by Sara Chipps on Stack Overflow See other posts from Stack Overflow or by Sara Chipps
Published on 2010-12-13T06:37:01Z Indexed on 2011/01/10 23:53 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

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();
  }

};

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about JSON