Refresh when loading image
Hello,
I have a problem when I have modified an image and asked AJAX to reload it.
Below is the code.
In a php procedure, I create dynamically a map of a different French area (called "department").
According to values found in a cookie several parameter are retrieved by the procedure. It could be :
- department name
- map size, -
- colors
Because the user has no button to trigger the refresh, this is done on an interval time basis.
Everything works fine except when the department name (that is the picture name) has not changed.
For exemple if I want just to modify the map size (not changing the name) it still display the previous picture.
(Of course I checked in my image folder that the new picture have been correctly created).
I spent hours debugging my php to understand why in this particular case things does not work, to finally understand it came from my ajax code.
In the php procedure after the image has been generated there is only one line returned :
echo ' <img src="./img/'.$ImageName.'" />' ;
I was wondering whether AJAX keeps in a sort of cache the last image ?
I tought of using a byapss in creating a randomly image name. But I'm pretty sure it could be a much better and cleaner way.
Thanks in advance for any explanation and ,if possible, a correction.
Gerard
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html lang="FR">
- <head>
- <title></title>
- <html><head> <meta http-equiv="Content-type" content="text/html; charset=Windows-1252"/>
-
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script>
- var minuteur =setInterval(function(){myTimer()},1000);
- var str ="";
-
- function myTimer()
- {
- if (readCookie("TailleCentre") == null) return;
- var options = readCookie("OPTIONS") ;
-
- if (options == null) options ="France";
- if (str != options)
- {
- clearInterval(minuteur);
- lancerAjax("#affichage") ;
- str=options;
- minuteur = setInterval(function(){myTimer()},1000);
- }
- }
- function readCookie(name)
- {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++)
- {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
- }
- return null;
- }
- function lancerAjax(id)
- {
- var request = $.ajax(
- {
- url: "affichage.php",
- type: "POST",
- dataType: "html"
- });
-
- request.done(function( msg )
- {
- $( id ).html( msg );
- });
- request.fail(function( jqXHR, textStatus ) {
- alert( "Request failed: " + textStatus );
- });
- }
- </script>
- </head>
- <body bgcolor="#D6E7CB">
- <center>
- <div id="affichage"></div>
- </center></body></html>