I have an array that I want to using each value from it in my GET request. Something like this : function something(){
function something(){
let test = ['something', 'other', ' test'];
let httpRequest;
function makeRequest(){
httpRequest = new XMLHttpRequest;
httpRequest.onreadystatechange = test;
for(var i = 0; i < test.length; i++){
(function(i){
httpRequest.open('GET', 'https://test.com/' + test[i] , true);
})()}
httpeRequest.send();
} make Request();
}
I keep getting undefined for test[i] though, and I’m not sure if this is how to correctly pass arrays through an httpRequest either. I will appreciate any help with this.
Yep I just saw that, but now my problem is I’m only getting the last value passed through even though its looping. I’m not sure why but I’m going to try to put the for loop over my Make Request function
I just made the for loop and called the makeRequest in it, then put parameters in my makeRequest function to pass in the array, in my console is very weird. It is passing me through the objects in my array, but it passes the last object twice, and then sometimes when it updates as I edit my project it returns undefined.
Yeah I had a forEach, but then I changed it to a for loop and now I’m having other issues, I’m just going to remake the whole thing because of all these bugs. It’s working now but I’m getting duplicate json responses and sometimes just get a response object with none of the users from my array, I get an object with a user called undefined sometimes.
I think I’m going to remove everything and read up on fetch or ajax since those look a lot easier to read and seem to perform better than XMLHttprequests.