Javascript – Content is cached

cachingjavascriptrefresh

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

Best Answer

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);