ajax question (forcing image refresh)

Posted on 2006-05-27
Last Modified: 2008-01-09
I have a function that calls a php page to rotate an image
                 var myurl = "rotate.php?img="+document.getElementById('r_img').value+"&r_dir="+document.getElementById('r_dir').value;"get", myurl, true);
         http.onreadystatechange = rotateIt;
That php page overwrites the image sent to it , rotates it 90 degrees and returns the same path of the image (after its been rotated and saved), when i get this image i refresh the src of the image
if (http.readyState == 4) {

What happens is that on the page the image shown is from the cach of the page (doesn't change) , if i delete the temporary files and refresh the page i see the new rotated image but i want it to be done without refreshing the page at all .
I guess one option is to rename the image when i rotate it , that could work but its a little complecated for me do do it now because all the images are stored in a database with some logic to their names so im hoping to find a simple solution that refreshes the cach of the image

Question by:nysurf1
    LVL 11

    Accepted Solution

    You need to ensure  that the no-cache HTTP headers are sent for the image.
    How you do this depends on how you are retreiving it from the server. If as a plain URL to the saved file then the simplest solution is that caching is turned off on the particular directory that they stored in.
    If you are retrieving them via a PHP program then this needs to output the headers before it sends the message body.
    LVL 4

    Author Comment

    Can you send me the code for the no-cache header , can i just put it in the header of the page where the images are loaded too?
    LVL 3

    Assisted Solution

    How about this?

    Or can you save the file to a different name?

    LVL 4

    Author Comment

    Thanks ,
    In the end i went with renaming the photo since the no-cache option is quite costly (its on a page with many images)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now