This code is supposed to loop through several webpages and find all the links on each page, listing them in console as it goes, but it seems to be listing only links from the very last webpage (fakeURL.com/735).
How I can get console.log(url);
to work for every iteration, instead of just the last one (which is 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();
}