Félix Gagnon-Grenier Félix Gagnon-Grenier - 7 months ago 8
HTML Question

How to make an image update on screen if the filename does not change?

I have an image

<img src="whatever.jpg">


An AJAX request uploads a different image to the server, replacing the file. When reloading I can see the new image.

How to make the image show the new file without reloading the page?

Answer

The solution posted here inspired a simple solution; add a timestamp to the query string of the src attribute when uploading the file with success.

<img src="whatever.jpg?2874652">

Which will cause browsers to reload the file from the server.