PDA

View Full Version : Image stuck in cache


snoodle
06-02-2007, 09:29 PM
I have a visual table filled with names from a database which allows you to click on a row to view further details of that record (which appear on the same page). One of the fields in the details section is an image, a photo of the selected person in the table. The images are kept in a folder on the server. Clicking on a row calls a javascript function that sets the image element's src to the appropriate file
(document.images.picture.src = thePhotoFileJPEG).

So far so good. Now the problem... I also provide for uploading of new photo files for each person (doing it the ajax way). All works fine... the uploaded file ends up in the correct folder. Also, if I upload a new photo for a person with an existing photo, I can see that the file gets copied over (by viewing the folder in Windows), however, the photo in my html image element still has the old image. Even if the javascript function is called again to set src = file with the new image, it uses the old image... until I refresh the screen.

How can I do a javascript "src = "whatever.jpg" and get the new copy of the file?

glenngv
06-05-2007, 06:30 PM
Append a unique and random string in the image URL.
document.images["picture"].src = thePhotoFileJPEG + "?d=" + Date.parse(new Date());

snoodle
06-08-2007, 01:32 AM
sorry - never answered this - thanks for the tip