javascript check if file exists on server
function doesFileExist(urlToFile) {
var xhr = new XMLHttpRequest();
xhr.open('HEAD', urlToFile, false);
xhr.send();
if (xhr.status == "404") {
return false;
} else {
return true;
}
}// checking existence of file synchronously
function doesFileExist(urlToFile) {
var xhr = new XMLHttpRequest();
xhr.open('HEAD', urlToFile, false);
xhr.send();
return xhr.status !== 404;
}function executeIfFileExist(src, callback) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (this.readyState === this.DONE) {
callback()
}
}
xhr.open('HEAD', src)
}
Also in JavaScript:
- splash screen react native
- script js
- js scroll to id
- javascript change frame background
- hoisting js
- react native textinput no keyboard
- jest Cross origin http://localhost forbidden
- document.queryselector picks first or last
- Better Array check with Array.isArray Because arrays are not true array in JavaScript, there is no simple typeof check. No problem! Use the method Array.isArray to check…
- validate gender in javascript
- ngmodel div angular 7
- jasmine compare arrays
- eslint disable block
- slice javascript string
- javascript object to array
- javasript array indexof
- js create object from array
- react hook usestate
- js get the week monday to friday date
- loading page for all ajax call in jquery 3.3.1
- javascript change color
- update react version
- base64 to blob
- match ids from 2 arrays in javascript asynchronous programming