I am really confused on a program that I made. A few days ago, it was working just fine, but now I am having problems with initializing it. I think I've figured out the source of the problem is basically the flow of the program is out of order but I have no idea why. Anybody have any idea how to debug this?
Debug Call Stack:
This
function init() {
createKeyArray();
createData();
}
Or this (createKeyArray)
function createKeyArray(){
$.getJSON("reps.json", function(data) {
$.each(data, function(key, val) {
console.log(key);
keyarray.push(key);
});
})
.fail(function(){
console.log("JSON extraction failed.");
});
};
Now during this period on the createKeyArray
this is where it gets really confusing, it goes to .getJSON
, runs it, then goes to my createData
function (skipping the $.each
function that pushes everything into keyarray.
It then runs createData
then goes BACK to the .each
part of createArray
function, runs that and then finishes running the rest of the program.
I am extremely confused whats going on and how to solve it. Appreciate any advice.