Since Javascript is single-threaded, I don't really know how this can be a problem but it goes like this: I have a function that gets called and in it another function. As soon as the Javascript starts executing the inner function, it simultaneously resumes with the outer function, when I actually want it to wait until the inner/nested function is finished and then go on. I hope this was understandable but I will elaborate further in comments:
function foo() {
"use strict";
//get some json file
$.getJSON("bar.json", function(data) {
//calculate something with data
//put the result in this div (innerHTML)
});
//display: block the div with results
}
The problem is that it immediately displays the div even if the calculation isn't finished yet. It will then throw in the result later, which is not at all what I want it to do. Do I have to do a promise or something like that?
Thanks in advance for your help. I appreciate it a lot.