I am currently working on a project where I need to utilize all the values from an array in my GET
request. The code snippet below outlines my approach:
function executeRequest(){
let data = ['value1', 'value2', 'value3'];
let httpRequest;
function makeRequest(){
httpRequest = new XMLHttpRequest;
httpRequest.onreadystatechange = data;
for(var i = 0; i < data.length; i++){
(function(i){
httpRequest.open('GET', 'https://example.com/' + data[i] , true);
})()}
httpRequest.send();
}
}
Despite setting this up, I keep receiving undefined values for data[i]
. I'm unsure if I am handling arrays correctly with the httpRequest
. Any guidance on how to resolve this issue would be greatly appreciated.