I'm new to js and I'm trying to perform multiple Get request within the same function
my code looks something like this:
...
...
...
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var response = JSON.parse(xhttp.responseText);
...
...
for(var i=0; i<response.length,i++)
{
...
var xhttp1 = new XMLHttpRequest();
xhttp1.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var response1 = JSON.parse(xhttp1.responseText);
...
...
...
}
};
xhttp1.open("GET","changedFileForTheInnerRequest",true);
xhttp1.send();
...
...
}
...
}
};
xhttp.open("GET","fileForTheOuterRequest",true);
xhttp.send();
My problem: I know it might seem odd but that seems to be my only option.
I'm generating a second GET request within the main one, for some reason when the inner one ended the js code stopped and seemed to think that he reached his end. I'm new to html and js so maybe that's the way that request works..
In conclusion, I'm trying to get some different files in the second GET request which is in a for loop, when the names are changing based on the i index and information from the first file that was loaded in the first request..
The problem is that when the first loop ends it never loops again and stays stack at the end of the first inner get.
will be so happy if you could help me, give me an alternative or just explain more
thank you!