views:

54

answers:

2

Hello, I am making a portal page for a project, and a div contained is refreshed every 1000 seconds.

The problem I am having though, is that the content that is being pulled in is always cached, so refreshing has no effect, the user has to do a hard refresh.

This only occurs in Internet Explorer

Here's the javascript code I used to refresh and load the div:

var auto_refresh = setInterval(
    function () {
  $('#news').load('apps/news.php').fadeIn("slow");
 }, 1000);

And as you can see, the data is contained in a PHP file.

contents of news.php:

<dl class="news">
  <dt>09/01/08</dt>
   <dd>
    <a href="#"><img src="/images/news1.jpg" alt="News image 1" /></a>
     <p><a href="#">Opal network services resume - Bada Bing!</a></p>
   </dd>
  <dt>07/01/08</dt>
   <dd>
    <a href="#"><img src="/images/news3.jpg" alt="News image 3" /></a>
     <p><a href="#">Anglia Contemporary Theatre - "Some news-pschitt!"</a></p>
   </dd>
  <dt>07/01/08</dt>
   <dd>
    <a href="#"><img src="/images/news4.jpg" alt="News image 4" /></a>
     <p><a href="#">ALSS Faculty Research Seminar - Novel Plots: Narrative in Nineteenth-Century Verbal and Visual Fictions</a></p>
   </dd>
  </dl>

How do I go about setting it so that the data is not cached?

Thanks

+6  A: 

add the current time to the query at the end of the url:

var auto_refresh = setInterval(
  function () {
  $('#news').load('apps/news.php?random='+(new Date()).getTime()).fadeIn("slow");
  }, 1000);
Marius
+1  A: 

Add no-cache into the caching directive for news.php or have a short cache 'say 500 sec' to improve performance for < 1000s refresh. Tweak the caching strategy to your your need.

Sample from http://www.php.net/manual/en/function.header.php:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
o.k.w
That's great, I thought it wasn't possible.
Shamil