'Check for newer versions of stored pages'

Posted on 2006-04-09
Last Modified: 2012-05-05

I'm using AJAX on my website, but internet explorer does not seem to actually be refreshing the data I retrieve via AJAX when I refresh the page. For example, I have a button that when pressed uses an XMLHttpRequest to go read some data from a database then returns it to the browser for display. It looks like:

    Press button
    XMLHttpRequest gets data from db
    XMLHttpRequest renders returned data in client browser

I can update the records in the database, ask the page to retrieve data but it doesn't seem to 'see' the new records unless I close the browser, and open a new instance. Then it picks up the changes.

Also if I go into the IE settings and choose 'Check for newer versions of stored pages: Every visit to the page' it works perfectly.

I can't rely on users to have chosen that setting though, so what can I do to get around this behaviour?

Question by:minnirok
    LVL 35

    Expert Comment

    put the current time in milliseconds into the URL as a parameter 'GET', 'yoururl.php?t=" + new Date().getTime(), true ) ;

    It will fool the browser into getting a new version of the page rather than just reading it from the cache :-)

    LVL 7

    Author Comment

    Hi Tim,

    Right now I'm already passing some params to my php script like:

        function DoIt()
            var vParams = "apple" + "," "orange";

  "GET", "myScript.php?param=" + vParams, true);

    How can I incorporate that time stamp?


    LVL 35

    Accepted Solution

"GET", "myScript.php?param=" + vParams + "&cachebuster=" + new Date().getTime(), true);

    should do it :-)

    And you may want to escape your params, just incase of spaces, quotes, etc...
    LVL 7

    Author Comment

    tres chouvette, merci beaucoup!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now