How do I check if a file on my server exists in jQuery or pure JavaScript?
This doesn't address the OP's question, but for anyone who is returning results from a database: here's a simple method I used.
If the user didn't upload an avatar the avatar
field would be NULL
, so I'd insert a default avatar image from the img
directory.
function getAvatar(avatar) {
if(avatar == null) {
return '/img/avatar.jpg';
} else {
return '/avi/' + avatar;
}
}
then