I was making a preloader using Ajax but It seems not to work. I want to load an image that if It's there the success does something -alert something-, but if It's not there just the error does another thing -alert another text-, but in this code It doesn´t matter if the image is found or not, both alerts happen no matter what, I mean if the image is found both alerts happen, but if I delete the photo both alerts happen as well, what could be the way to achieve this guys with ajax's complete and error? Thanks for any guideline in this one.
function preloadImages()
{
var $image = 'http://www.mysite/images/example.jpg';
jQuery.ajax({
url: $image,
complete: function(){
fileLoaded();
},
error: function(){
errorLoading();
}
});
}
function fileLoaded(){
alert('There is the image');
}
function errorLoading(){
alert('No image');
}
Thanks for any help in advance. Greetings.