The current code is designed to iterate through multiple webpages, extracting all the links on each page and listing them in the console. However, it appears that only the links from the last webpage (fakeURL.com/735) are being displayed.
Is there a way to make console.log(url);
work during every iteration, instead of just the final one (when i=735)?
for(i = 0; i <= 735; i += 15)
{
var xhrs = new XMLHttpRequest();
xhrs.open("get", 'http://fakeURL.com/' + i, true);
xhrs.onreadystatechange = function()
{
if (xhrs.readyState == 4)
{
$(xhrs.responseText).find('a').each(function()
{
var url = $(this).attr('href');
console.log(url);
});
}
}
xhrs.send();
}