var req = new XMLHttpRequest();
req.open('GET', '20121209.xml', false);
req.send(null);
if(req.status == 0)
{
//file exist
}
I want to check whether file is existed or not in local machine using javascript. So I wrote the code like above. I can check when file is existed, but I cannot check when the file is not existed.
Finally I want to do something when file is not existed. Can I do this???
if (req.status == 404) { //doesn't exist }Also, it works only if you are executing the JS from afile://url. If running it on HTTP you can't access the local file-system.