getJSON is called asynchronously, so you are not getting what you expect.
Let me explain:
function getFooterContent(){
//ajax call to get json file
$.getJSON("scripts/pageData/footer/footerData.json",
function(jsonData){ // This function is executed when request is ready and server responds with OK
console.log(jsonData);
return jsonData;
}).
fail(function(){ // This when servers responds with error
console.log("fail");
return -1;
});
//Return the json file
// You are returning undefined actually
}
function someFunction(){
var someContent = new Object();
someContent = getFooterContent();
console.log(someContent);
}
You need:
function someFunction(){
var someContent = new Object();
getFooterContent(function(someContent){
// someContent is passed by getFooterContent
console.log(someContent);
});
}
Here is how you pass arguments to a callback JavaScript: Passing parameters to a callback function
For your function it will be:
function getFooterContent(done, fail){
$.getJSON("scripts/pageData/footer/footerData.json",
function(jsonData){ // This function is executed when request is ready and server responds with OK
// console.log(jsonData);
// return jsonData;
done.call(null, jsonData); // or done.apply()
}).
fail(function(){ // This when servers responds with error
// console.log("fail");
// return -1;
fail.call(); // or fail.apply()
});
}