ajax question (forcing image refresh)

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;
         http.open("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) {
       document.getElementById(document.getElementById('id_img').value).src=http.responseText;

  }
*************
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
Thanks!!

LVL 4
nysurf1Asked:
Who is Participating?
 
mouattsConnect With a Mentor Commented:
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.
HTH
Steve
0
 
nysurf1Author Commented:
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?
thanks
0
 
a122178Connect With a Mentor Commented:
How about this?

Or can you save the file to a different name?

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

http://www.i18nguy.com/markup/metatags.html
0
 
nysurf1Author Commented:
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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.