Link to home
Start Free TrialLog in
Avatar of Lmillard
Lmillard

asked on

Force browser to refresh page when using ajax with Coldfusion

Hi,

I am seeing issues with a heavily Ajax reliant application I have written where the users browser is not not automatically refreshing the page content when required and still using the cached version.

I initially though that this was IE only but it would appear that Chrome is having the same issue on the Mac.

Can anyone suggest a way to code around this and force the browser to recognise the new content?
At the moment I am having to instruct the client to ensure that all browsers cache setting are manually adjusted.

Cheers
Leigh
Avatar of jazzIIIlove
jazzIIIlove
Flag of Sweden image

Hi there;

This may be helpful for you:

Best regards.
<html>
<head>
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
</script>
</head>
<body onload="JavaScript:timedRefresh(5000);">
<p>5 second refresh.</p>
</body>
</html>

Open in new window

Avatar of Lmillard
Lmillard

ASKER

Hi, Thanks for this but it is a server content that is being read from cache rather than being read from the server. i.e a customer record is amended via an update form but if the record is viewed again the change is not viewable on the webpage although it has been applied correctly in the database.

I am attempting to force the server side code to be re-read with each visit to the page. In IE this can be achieved via the Tools --> Internet Settings --> General  tab where there is a 'check for newer version of stored pages' setting but this is not available in all browsers so I am trying to force this to happen with server side Coldfusion code.

Regards
Leigh
ASKER CERTIFIED SOLUTION
Avatar of kadaba
kadaba
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this a guaranteed method to get around the issue? if so I will add this to the top of each page.
@kadaba

It's worth noting there are "no-cache" headers (ie directives) you can add to each page to indicate the page should not be cached. But the only thing that's ever worked reliably for me in the past is what @kadaba's suggested.  Adding a random string/timestamp makes the browser think it's viewing a new page ie something it hasn't seen before.