for (var i = 0; i < array.length; i++) { (function() { var xhr = new XMLHttpRequest(); xhr.open("GET", array[i], true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { console.log(xhr.responseText); } } xhr.send(); })(); }