jQuery: how to check if file exists

var base='http://mizine.de';
var url='/image_path_to_test.jpg';
var fallback_url='/image_path_exists_for_fallback_image.jpg';

/** Asynchronous!!! **/
$.get(base+url).done(function(){
  $('#any_DOM_id').append('<img id="my_image" src="'+url+'"/>');
}).fail(function(){
  $('#any_DOM_id').append('<img id="my_image" src="'+fallback_url+'"/>');
});

@public #jquery #js #javascript #file #exist #test

Hint: $.get() is asynchronous, so this way 'll kill the sequential chronology of your script execution