1

I have single ajax application in java. I am working with lots of file type images. But some file has no extension or may be bed extension(Non-popular) in this case i replace with default image in "javascript". Here I want to checkout at server side for each image request. and if image path not found then i want to replace with default image.

My existing scenario is below:

In Javascript

function getDefaultFileImageName(image){
    image.onerror = "";
    image.src = "Images/32px/_blank.png";
    return true;
}
<img src='Images/32px/pdf.png' onerror='getDefaultFileImageName(this)' />

i have lots of images on page so in this case i get out put in firebug like this: enter image description here

so i want server side-Java solution. So if image not exist then server self return default image.

Rickyrock
  • 328
  • 2
  • 4
  • 21

3 Answers3

0

I believe this might be what you're looking for:

https://stackoverflow.com/a/3327673/2040509

$(".myimage").error(function(){
  $(this).hide();
});

$(".myimage").load(function() {
    $(this).show();
});
Community
  • 1
  • 1
MarioD
  • 1,703
  • 1
  • 14
  • 24
0

You need to remove onerror method from your function:

function getDefaultFileImageName(image){
    image.src = "Images/32px/_blank.png";
    return true;
}
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0
$( document ).ready(function() {
    $("#MyPicture").onerror = function () {
      this.src = 'error.png'; // Error image
    };
}); 

<img src='Images/32px/pdf.png' id="MyPicture" />
Deepu--Java
  • 3,742
  • 3
  • 19
  • 30