Don E Posted July 31, 2012 Share Posted July 31, 2012 Hello everyone, I was wondering if it's possible to update an image on a webpage without having to refresh the page so that the updated image can be displayed? I know that ajax will be involved and I have tried it but when echoing the new image in the PHP that process/makes changes to the image, it doesn't display the new updated image. I did a bit of searching and some have said the update may not be taking place because the 'cached' version of the image is being displayed? I'm not sure. The only way I was able to get this to work is when after processing the image, I have the browser refresh using: window.location.reload(); Any input is greatly appreciated, thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 31, 2012 Share Posted July 31, 2012 To make sure the cache isn't used it's common to append a querystring to the filename with a unique or random number, which will force the browser to get the file again. Link to comment Share on other sites More sharing options...
Don E Posted July 31, 2012 Author Share Posted July 31, 2012 Thanks JSG. When I try the following in the ajax call to the image modifying script: echo '<img id="image" src="../uploads/' . $_SESSION['picName'] . '?d=' . time() . '" alt="Image" />'; .. it doesn't append to the file and no image is displayed. Maybe I'm not appending correctly? (Note: $_SESSION['picName'] is just contains the name of the image, like: mypic.jpg) Thanks again. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 31, 2012 Share Posted July 31, 2012 Right, maybe you're not appending correctly. Link to comment Share on other sites More sharing options...
Don E Posted July 31, 2012 Author Share Posted July 31, 2012 At this link: http://davidwalsh.name/prevent-cache I basically did what's shown but it's shown for CSS files and JavaScript to prevent cache. When trying the following by removing 'd=', it still doesn't display the image: echo '<img id="image" src="../uploads/' . $_SESSION['picName'] . '?' . time() . '" alt="Image" />'; Link to comment Share on other sites More sharing options...
justsomeguy Posted July 31, 2012 Share Posted July 31, 2012 Then I would think that the filename is probably not the issue. It's probably how you append the image. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now