var dataGet = [];
var data = JSON.stringify(false);
for (i = 0; i < 5; i++) {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === this.DONE) {
var name = this.responseText;
var n = name.search("my_var");
var IL = name.substr(n + 17, 4);
IL = IL.replace(/\D/g, '');
IL = parseInt(IL, 10);
dataGet.push([174 + i, IL]);
}
});
var url = "my_url".concat(174 + i).concat("my_url_suffix");
xhr.open("GET", url);
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-auth-token", "my_auth_token");
xhr.send(data);
}
for (i = 0; i < 5; i++) {
console.log(dataGet[i, 0]);
}
I'm trying to fill up dataGet with the data I pull from the website. It just spits out five lines of "undefined". If I use console.log within the if statement, it'll spit out the correct values. How do I put those values in a data construct other than console.log? I'm using node.js with XMLHTTPRequest - and I have no idea how any of this works.
Thanks in advance -A complete newb