Last active
July 20, 2018 22:22
-
-
Save vdite/11369781 to your computer and use it in GitHub Desktop.
jQuery: how to check if file exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+'"/>'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I was searching something like this and I found it, thanks hehehe.
This is my code, I was trying to place in drupal custom view-template a file reader and validate if the image exist or not, in php is easy to read a directory but twig doesn't have this function, but fortunatly you have the way I was searching at las resource.
This is my code:
Thanks for the Post...