?
Solved

'Check for newer versions of stored pages'

Posted on 2006-04-09
4
Medium Priority
?
1,137 Views
Last Modified: 2012-05-05
Hi,

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?

Thanks
0
Comment
Question by:minnirok
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 16412356
put the current time in milliseconds into the URL as a parameter

    ajaxobj.open( '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 :-)

Tim
0
 
LVL 7

Author Comment

by:minnirok
ID: 16413301
Hi Tim,

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

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

        httpGetStuff.open("GET", "myScript.php?param=" + vParams, true);
    }

How can I incorporate that time stamp?

Thanks

     
0
 
LVL 35

Accepted Solution

by:
TimYates earned 2000 total points
ID: 16413317
      httpGetStuff.open("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...
0
 
LVL 7

Author Comment

by:minnirok
ID: 16414158
tres chouvette, merci beaucoup!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

807 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