Welcome Guest, Not a member yet? Register   Sign In
[solved] changing images with jquery
#1

[eluser]SPeed_FANat1c[/eluser]
I change images in my div container using this line:

Code:
$('div.foto').html('<img src="'+ CI.base_url + 'uploads/darbuotojai/' + response + '"/>');

response variable is the file name.

The user first time uploads image file with ajax. The file is renamed to 'worker.jpg'. Then it is shown in web page.
Then user decides to change the file - uploads another. The file is renamed to 'worker1.jpg' because there exists already 'worker.jpg'. The 'worker1.jpg' is shown on the webpage. The 'worker.jpg' is removed from server.
And then the user decides once more to change the file. So he uploads againg, and the file gets name 'worker.jpg' - the one which was the first time, because this file name is free now, there is no more such name in the server. Then show that file.
And the problem - the browser shows that file which was uploaded for the first time, which is removed from server. It remembers it. How to make it show the new file which is with the same name? In other words browser should get new file instead of using old.
#2

[eluser]Madmartigan1[/eluser]
Yeah, it's stuck in the browser cache.

You can try appending some random junk to the end of the filename:

worker.jpg?timestamp=1234567890

You can leave worker.jpg on the server and make the new file worker3.jpg instead.
You can display the image in an iframe, and refresh the iframe when the new image is uploaded.

Can't think of anything else. I looked for a solution to this myself (doing image cropping) and never found one that was perfect.
#3

[eluser]SPeed_FANat1c[/eluser]
"worker.jpg?timestamp=1234567890"

This works fine, thank you.




Theme © iAndrew 2016 - Forum software by © MyBB