I would like to create about 10 XML HTTP requests as below. I would like to use the value of i for the first “children” reference, but as i changes before the callback is executed, the value of i mismatches the url taken in “results” tab. How can I generalize this?
var i = 1;
WinJS.xhr({
url: root.results[i].profile_image_url_https,
responseType: 'blob'
}).done(function (result) {
var imgTag = theDiv.children[1].children[0];
var imageBlob = URL.createObjectURL(result.response, {
oneTimeOnly: true
});
imgTag.src = imageBlob; //tempLocalUrl;
});
i = 2;
WinJS.xhr({
url: root.results[i].profile_image_url_https,
responseType: 'blob'
}).done(function (result) {
var imgTag = theDiv.children[2].children[0];
var imageBlob = URL.createObjectURL(result.response, {
oneTimeOnly: true
});
imgTag.src = imageBlob; //tempLocalUrl;
});
the typical way is to use an extra function (immediately executed) to capture the current value of your loop variable, e.g.: