Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Problem with refreshing the image with same name using attr('src',newimage)

I am trying to refresh an image on the page but it is not happening. I have a page with images and I need to update those images as required. To update an image I upload the image on a lightbox and then close the lightbox. The image on the page should update itself. Now, I tried $('#imageid').attr('src', newimage). I want to make a special mention here that the name of both the old and new images are same. And I feel this is the problem. If I hard code any other image it does appear as soon as the lightbox closes. But, when I try to refresh the image by putting the same image name for the 'src' attribute then nothing happens.

Can someone help me out how I can fix this issue and show the updated image.

Thanks.

Edit: Could it be the cache?

like image 813
Blueboye Avatar asked Dec 29 '22 20:12

Blueboye


1 Answers

There's probably a better solution, but you could just throw on a parameter to force a new image load.

i.e.: Set the src to newImage+"?"+(new Date()).getTime()

like image 135
Stefan Kendall Avatar answered Jan 26 '23 00:01

Stefan Kendall