How can I check using javascript or jQuery that a file exists?
OBS : I opened the question and I already answered.
How can I check using javascript or jQuery that a file exists?
OBS : I opened the question and I already answered.
Below are the means that I have found.
function verificaUrl(url) {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status != 404;
}
$.ajax({
url:'http://www.exemplo.com.br/arquivo.txt',
type:'HEAD',
success: function() {
//arquivo existe
}
error: function() {
//arquivo não existe
},
});