Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Last active March 7, 2018 21:21
Show Gist options
  • Select an option

  • Save LiamChapman/ae35eb1c49bd34a0440db8b409a6f103 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/ae35eb1c49bd34a0440db8b409a6f103 to your computer and use it in GitHub Desktop.
Check if a file exists with it's http status (200) with a promise
window.httpStatus = (address) => {
return new Promise( (resolve, reject) => {
let client = new XMLHttpRequest();
client.onload = function () {
if (this.status === 200) resolve(this.status);
if (this.status !== 200) reject(this.status);
};
client.open("HEAD", address, true);
client.send();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment