I got 50 JSON files. (1.json, 2.json ... 50.json). The structure for each one is:
{
"book": "Księga Wyjścia",
"chapter": 1,
"type": "verses",
"verses": [
{
"text": "Oto imiona synów Izraela, którzy razem z Jakubem przybyli do Egiptu. Każdy zaś przyszedł ze swoją rodziną:",
"verse": "1"
},
{
"text": "Ruben, Symeon, Lewi, Juda;",
"verse": "2"
},
{
"text": "Issachar, Zabulon i Beniamin;",
"verse": "3"
},
{
"text": "Dan, Neftali, Gad i Aser.",
"verse": "4"
},
{
"text": "Było zaś wszystkich potomków Jakuba siedemdziesiąt osób, Józef zaś już był w Egipcie.",
"verse": "5"
}
]
}
There are more verses in every file and the size of each one can be completely different (so they don't load immediately). I load "chapter" node. Each time I refresh the file, I got different order, ie. (just last few numbers from last reshresh): 28,35,32,36,37,29,30,31,38,33,49,50,39,40,41,42,43,44,45,46,47,48
<script>
for (i = 1; i <= 50; i++) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var input = JSON.parse(this.responseText);
console.log(input.chapter);
}
};
xmlhttp.open("GET", (i + ".json"), true);
xmlhttp.send();
}
</script>
I assume it's because it loads asynchronous. Can I force my script to load synchronous?
falseas value for the async argument. Embrace the power of promises and asynchronous programming instead.