Check if image exists on server

Check if image exists on server

Hi,

I am trying to check if an image exist on the server then I can display it otherwise display a default image.

Using below code:

  1. $.ajax({
  2.     url: 'https://people.softnames.com/images/home/splash/NASSER/4.png',
  3.     crossDomain: true,
  4.     success: function (data) {
  5.         alert('exists.. display this image');
  6.     },
  7.     error: function (data) {
  8.         alert('does not exist. display an alternative default image here;');
  9.     },
  10. });


but it returns an error although the above url does return an image.

Kindly help...


Thanks,