I do load it immediately, but I have other functions which rely on the data being loaded, and currently they are firing before the getJSON function is completed. I need some way to check that the data has been loaded before executing those functions. I'm sure there's some sort of event I should be checking, Ijust don't know which/how.
On Aug 22, 2:52 pm, GLP <[EMAIL PROTECTED]> wrote: > Just load your JSON data as early as possible. What are you waiting > for to not load the data immediately after the 'document is ready' ? > > cbandes schreef: > > > Hi - > > > I have a simple json file which contains a list of key/path pairs, the > > idea is that I will use this to update the links in a nav menu. > > > In order to do this, I am usinggetJSONto load and parse the data, > > like so: > > > var pathAssoc = new Array(); > > var pathVar = null; > > > function getPathData(){ > > $.getJSON("js/paths.js", function(data){ //gets the json object > > //alert(data.paths[1].name); > > //pathArray = data.paths; //creates an array out of our > > returned > > data > > for( var i in data.paths){ > > var name = data.paths[i].name; > > var path = data.paths[i].path; > > pathAssoc[name]=path; > > } > > if((page!="")&&(path!="")){ > > restoreLocation(); > > } > > }); > > } > > > My problem is that since it's an asynchronous request, other functions > > are trying to access pathAssoc before it is ready. What event should I > > be using/listening for in order to make sure pathAssoc is populated > > before continuing? > > > Current dependent functions: > > > function getPagePath(name){ > > pathVar = pathAssoc[name]; > > } > > > So if I call getPagePath() before getPathData() is finished, > > everything (predictably) breaks...