3
votes

I'm using

$("#my_img").attr("src", "/another_img.png");

inside the "beforeSend" callback of an Ajax request using jQuery, the problem is that the the img isn't being always refreshed to the user, sometimes I saw the new image and sometimes not, is there anyway to force the refresh of the img ? I was thinking that by changing the "src" attribute of the img element was enough to make the engine refresh the image. Thanks !

1

1 Answers

4
votes

Sounds like it might be a caching issue, try:

$("#my_img").attr("src", "/another_img.png?v=" + new Date().getTime());