Last active
March 7, 2018 21:21
-
-
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
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
| 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