I'm using a code similar to the simplified one below to search through several pages of posts on a forum website and then list the links in console.
$(document).ready(function () {
for(i = 0; i <= 735; i += 15) {
var xhrs = new XMLHttpRequest();
xhrs.open("get", 'http://fakeURL.com/' + i, true);
xhrs.onreadystatechange = function()
{
if (this.readyState == 4)
{
$(this.responseText).find('a').each(function()
{
var url = $(this).attr('href');
console.log(url);
});
}
}
xhrs.send();
}
}
The problem is that sometimes I'll get errors like this in console:
Resource interpreted as Image but transferred with MIME type text/html: "dailydawdle.com/".
Error: GET http://puu.sh/4Ueom.png 404 (Not Found) 4Ueom.png:1
Error: GET http://thisUrlIsTooLong.jpg 403 (Forbidden) cellphonebuyers large verge super wide.jpg:1
These errors usually don't stop the code from finishing the list of urls, but one time it exited the webpage and went to a red screen in chrome that said something like 'security error'.
- Why do these errors occur and how do I stop them?
Even if I only search each page for links that begin with a certain string I get these errors. I'm saying that even if I replace find('a')
with find("a[href^='http://forum.posts/']")
so that only the forum's links are searched through, I still get errors with outsider website links (posted by people in the forum probably) and sometimes a red warning page that says 'security error'.
- Why am I getting errors on links that don't even begin with the string I specified to search for?