I need to get the right i
values for each and every one of my response
values (JSON loads). How do I do that?
Lets say I have 10 JSON files. All of them must be loaded, stored and displayed to the client in the proper order.
So it should look something like this:
for (var i = 0; i < files.length; i++) {
$.getJSON(files[i], function (response) {
console.log(i);
console.log(response);
});
}
The result of the response
is what we would expect - the contents of the file, but the variable i
always seems to be the same (= files.length). My explanation for this would be that JS is not a language that waits for a specific action to complete, it can do a lot of actions in the same time (forgot the scientific name for this).