I'm writing a simple utility to handle the numerous JSON calls I have to make in my app, but the problem with the readJson function below is that it completes before the inner function that gets the Ajax has got the data, so it returns undefined. Can anyone point me to an existing answer to this issue, or offer any advice on how to better structure this function so that it doesn't return until the Ajax request is complete?
json_manager = {
thisJson:'',
readJson:function(theFileName, thePathName) {
var theUrl=(thePathName+theFileName);
$.getJSON(theUrl).done(function(theJSON) {
json_manager.thisJson=theJSON;
});
return(json_manager.thisJson)
},
//more functions
}