javascript/jquery test image URL for update

Is there a way though the DOM to test an image URL to see when it was last updated?

I am uploading an image to the web server. The image will replace a previous image with the same URL. I'm using plupload via ajax. When the upload is done, I want to update the image on the page.

I have tried using the FileUploaded event to trigger updating the src on the image. But I think it's either pulling the image from cache or it's firing faster than the web server can server the new image.

I know I could hack it by sleeping a couple of seconds. But I can think of all kinds of reasons why that would fail.

Is there a way to read a header from the file to tell if the file has changed on the server? Then I can keep asking until it does?

A more elegant solution would of course be better.

Thanks

Answers


Since you say you're loading the image from the same URL, you need to trick the browser so it doesn't get the image from the cache. Appending the time should do it...

$("img").attr("src", "/image.png?t=" + (new Date().getTime()));

Need Your Help

Using mysql to replace img src? NEWBIE

mysql image wordpress phpmyadmin src

I tried to use the Enable Media Replace ( http://wordpress.org/plugins/enable-media-replace/ ) to replace some images on my site with updated versions. There is an option to update all instances wh...

Reload web page in GWT

javascript gwt

After a user logged and press my page url in this page if user press confirm button i want to relaod my page not the home page