I have a web page which I need to check if files exist, they vary in files sizes and file type, I have the below code working but for larger files it can take a long time (one of them took 30 seconds) to return a result. What I want to know is there a better way, something that if it was a conversation would look like:
"Are you there file?"
"Yes. I am here and last Sunday I wa.. "
"ya, ya, ya your there shhh"
function fileExists(url) {
if(url){
var req = new XMLHttpRequest()
req.open('GET', url, false)
req.send()
return req.status==200
} else {
return false
}
}
So anyone know of a better way which doesn't have to load as much of the file or can cancel the loading once it knows the file is there.
Aucun commentaire:
Enregistrer un commentaire