Roly
Roly

Reputation: 161

img src not working as expected using JS/JQuery: previous image get displayed instead of new uploaded image

I have a form to upload images. By default the source is "images/noimage.png";

<img id="previewing" src="images/noimage.png" />

I store the path in the database. If I select a specific user and the form gets loaded I want to display the image for the specific user. I do this in the windows.onload event. However another image (previous image the user had, if user had one) gets loaded instead of the new one.

var Logo = 'Logos/123.png'; //path stored in Database

if (Logo!='') {
  //If the user has a 'Logo', show it
   $("#previewing").prop("src", Logo);
} else { 
  // if user has no 'Logo', show default image
   $("#previewing").prop("src", 'Images/noimage.png');
}

This does not work as expected. What's wrong here?

Upvotes: 0

Views: 47

Answers (1)

Furquan
Furquan

Reputation: 1852

If after reloading image getting change then most probably its Caching issue. you may try adding some random string into image URL like

Logos/123.png?v=xyz

Upvotes: 3

Related Questions