tags:

views:

238

answers:

3

Hey guys, I have a weird problem. I have an update system that refreshes data on a time interval. It works well in all browsers except internet explorer 8. The problem is that once it loads the data, it does not matter if the data updates further, it will not update the data visually until the internet history is cleared. I am not using any cookies server-side...Anyone ever encounter something like this?

Here is my javascript, thanks for any assistance in advance

function prepare(response) {
          var d = new Date();
          count++;
          d.setTime(response.time*1000);

          var mytime = d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
          var string = '<li class="shoutbox-list" id="list-'+count+'">'
              + '<span class="shoutbox-list-nick"><a href="statistics.php?user='+response.user+'">'+response.user+'</a></span>'
              + ' <span class="date">'+mytime+'</span><br>'
              + '<span class="msg">'+response.message+'</span>'
              +'</li>';

          return string;
        }
 function refresh() {
          $.getJSON(files+"shoutbox.php?action=view&time="+lastTime+"&topic_id="+topic_id, function(json) {
            if(json.length) {
              for(i=0; i < json.length; i++) {
                $('#daddy-shoutbox-list').prepend(prepare(json[i]));
                $('#list-' + count).fadeIn(1500);
              }
              var j = i-1;
              lastTime = json[j].time;
            }
            //alert(lastTime);
          });
          timeoutID = setTimeout(refresh, 3000);
        }
       $(document).ready(function() {

            var options = { 
              dataType:       'json',
              beforeSubmit:   validate,
              success:        function(response, status){
                  if (response.error=='success'){
                     success(response, status);
                  }
                  else {
                      $.prompt(response.error);
                  }
              }
            }; 
            $('#daddy-shoutbox-form').ajaxForm(options);
            timeoutID = setTimeout(refresh, 100);


        });
+2  A: 

This sounds like a caching issue. Try appending a random string to the URL to ensure that it gets changed.

var url = 'example.php?foo=bar&r=' + Math.random();
Matchu
I would simply append a timestamp instead of a random number: `"...`
Cory Larson
Heh. It's probably pretty obvious that I haven't had to deal with this sort of thing very often.
Matchu
Well, +1 anyway, because you had the right idea. Another thing -- this caching thing has happened in IE6, IE7, and IE8 for me, so this is my default solution. I'm not sure why jQuery doesn't just build this into their framework as a configurable option.
Cory Larson
The timestamp worked thanks everyone for your help, really appreciate it, you guys are great.
Scarface
An even shorter method is `var url = 'example.php?foo=bar`. The unary operator `+` converts `new Date()` into an integer, which is then cast as a string automatically.
Ron DeVera
yeah good point.
Scarface
+4  A: 

You should probably check your cache control on the server, this seem to in cause here. You can probably add a "no-cache" http header to your result.

Laurent Bourgault-Roy
Somehow I always forget that there are non-hacky solutions to certain problems. +1, leaving answer for reference.
Matchu
thanks anyway man, but I tried denying caching and it did not work properly. Maybe I did it wrong, I used a php headerheader("Cache-Control: no-cache, must-revalidate");
Scarface
Did you check the headers sent by the server? You can do it easily with Firebug or the IE developper tool.
Laurent Bourgault-Roy
A: 

Hi, I am facing the same issues with all the IE versions. On Mozilla and other versions everything works really good. I have tried appending a timestamp with the URL, add response headers in the JSP's and also controlling the no-cache from server. Nothing seems to work with the Internet Explorer. Any suggestion would really be appreciated.

Sid.

Siddhartha