Reputation: 3068
Image gallery page has a table containing 12 images. User can update image by clicking on desired image and uploading a new photo. Images are all named 01.jpg, 02.jpg, etc., 12.jpg. When new image is uploaded, it is automatically resized and given the same name as the image it is replacing.
Problem: when upload dialog is closed, the image in the file system has changed, but the image on screen is still the old image. (Note: if I rename the image in the filesystem and in the img tag, then the image changes on screen).
I tried clearing the table cell of the old img element, and replacing it with ... well, the identical code:
$("#td_02").html("");
$("#td_02").html('<img id="img_02" class="gimg" src="img/gallery/thb_02.jpg" />');
Disappointed, but not too surprised that the image didn't change.
How can I force the browser to refresh the image?
Upvotes: 0
Views: 350
Reputation: 7794
You could append a query string to the end of the image, that way it should clear the cached image, so thb_02.jpg?blahblah
or a get the current timestamp if you want it to be a unique value to make sure it always grabs the latest image.
Upvotes: 3