I'm trying to write a "fileExists" function in Javascript which simply sends a request to the server and returns false if a 404 status is sent back.
The function works perfectly, but I can't seem to suppress the error message I get in the Google Chrome console stating: GET /something/foobar 404 (Not Found)
.
Does anyone know a way to work around this?
For reference, here's the code I'm using:
var fileExists = function(url) {
var req = new XMLHttpRequest();
req.open('GET', url, false);
req.send();
return req.status === 200;
};
Thanks in advance!