tags:

views:

712

answers:

3
<img src="test.php" />

where test.php generates an image with a random number.

Itried :

$('#verifyimage').click(function() {
        $(this).attr('src',$(this).attr('src'));
    });

But it doesn't work.

A: 

Add a timestamp or a random number:

var timestamp = new Date().getTime();
$(this).attr('src',$(this).attr('src') + '?' +timestamp );
Kobi
+6  A: 

You can force a refresh by appending a random string at the end, thus changing the URL:

$('#verifyimage').click(function() {
    $(this).attr('src', $(this).attr('src')+'?'+Math.random());
});
K Prime
Eww. No, don't. Set appropriate caching response headers on the server instead.
Nicolás
`Cache-control`, `Expires`, et al. only work once a HTTP request is received - the above is simply to force the client to make that request. In the absence of a `Image.reload` (AFAIK), this was the simplest method to make a new request
K Prime
would suggest substring on the src attribute to a "?" so that after the first time, it doesn't keep appending more querystring data...
Tracker1
A: 

In test.php set the headers of Content-Type: to image/jpeg

claws