I am using MSXML2.ServerHTTP in Jscript (ECMAScript 3)to retrieve some data - I send multiple requests (as I can only retrieve 1,000 rows per request). The number of multiple requests varies, as the total varies. Included in the requests is a function to process the data (push it into an array) once the data is received. Code looks similar to the below;
var H = []; x = 0
for (var i = 0; i<L; i +=1000)
{H.push(new ActiveXObject('MSXML2.ServerXMLHTTP'));}
for (var i = 0; i<L; i +=1000)
{H[x].open('GET', 'https://someurl.com', true);
H[x].setRequestHeader('Content-Type', 'application/json');
H[x].onreadystatechange =
function(e)
{if (H[x].readyState === 4 && H[x].status === 200)
{J.push(H[x].responseText);}};
H[x].send(); x++}
So what happens is that my loop runs like 5x (as L is 4700 for example), and X increments from 0 to 4 - however, once the data gets retrieved, the function 'e' looks at the then value of x instead of the value when it gets initialized.
So let's say the 2nd data request gets back - it sees that it's done, executes function e, but that function the looks at the current value of x (which would be 5 after 5 loops) and thus do nothing as there is no H[5]...
Is there a way to set the value of x as a constant in that loop?
Thanks!