Last active
April 15, 2018 03:38
-
-
Save luislobo14rap/b59ccec57d2b3e7fa6ba8cb82e25f632 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ajaxGetStatusOfLinks(arrayOfLinks) { | |
if (typeof arrayOfLinks == 'string') { | |
arrayOfLinks = [arrayOfLinks]; | |
}; | |
let returnObjs = []; | |
arrayOfLinks.forEach(function(link, i) { | |
let xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.status == 200 && this.readyState == 4) { | |
returnObjs.push({ | |
'link': link, | |
'status': 200 | |
}); | |
}; | |
if (this.status == 404 && this.readyState == 4) { | |
returnObjs.push({ | |
'link': link, | |
'status': 404 | |
}); | |
}; | |
}; | |
xhttp.open('GET', link, true); | |
xhttp.send(); | |
}); | |
waitRetunsLength = setInterval(function() { | |
let reOrder = []; | |
if (returnObjs.length == arrayOfLinks.length) { | |
clearInterval(waitRetunsLength); | |
arrayOfLinks.forEach(function(link, i) { | |
returnObjs.forEach(function(objLink, j) { | |
if (objLink.link == link) { | |
reOrder.push(objLink); | |
}; | |
}); | |
}); | |
return reOrder; | |
}; | |
}, 10); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment