I don't know if this is really something I can fix via Prototype, or if it's in any way a Prototype issue, but I'll try here first. Here is my problem - which unfortunately I can’t show you because I'm only developing it on my local system at the moment - slightly simplified:
I have a pair of images on a page, one above the other. The user should be able to click the second one to swap them round, but I don't mean merely swapping their position on the page: this involves renaming the files. On the server, the first image is given a completely new name and the second is renamed with the first's old name. The div containing the two is then replaced by the magic of Ajax, except... the problem is that the image with the old name is cached (I think), so although the second image is indeed replaced by the first with its brand new name, the first image is unchanged, either because the previous image with that name is stuck in the cache or because it hasn’t had time to be reloaded due to the asynchronous nature of the process. Either way, I end up with two of the same image. If I then refresh the page altogether, I get the correct images. In sequence, this happens: - User clicks image - Ajax request is created, running a php script with various parameters, in which... - ...the necessary renaming takes place (which involves checking for duplicates etc.), then... - ...a php file is included* which does various processing to build up an output string for the replacement div... - ...in which all <> are replaced by [] so as not to confuse the xml return. - Back in JS, the [] are changed back to <> and the containing div is replaced. So is my problem the cache? Or is it simply that the scripts run faster than the replacement image can be loaded? I've tried various things to stop it caching, such as loading the top image via a tiny php script which sends all manner of no-cache type headers then does fpassthru, fread or whatever (I've tried it various ways) - this made no difference. I even tried including a sleep(1) command in this script! - no good. I've also tried preloading the image in JS before the new div is output - no good. Should I be trying to subvert (pervert?) Ajax into running synchronously somehow? I'm quite prepared to accept that I may be approaching this whole problem bass-ackwards, and would be grateful for any pointers. * I did this via an include file because I need to do the same processing when the page is initially loaded, so this seemed the most efficient way, code-wise. -- Cheers... Chris Highway 57 Web Development -- <http://www.highway57.co.uk/> -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
