Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Caching

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
Being very new to AJAX and JS I hope you can tolerate what is probably a stupid question.

Every time I modify any of the code I have to unload IE & reload to get the code changes reflected in the output.

It seems OK in PHP. if I delete the file on the server it will still somehow manage to run it

Any ideas please
 
Found it

IE7 Browser

tools -> internet options -> Temporary internet files -> settings-> Check for new versions of stored pages Click on Every visit


Hope that may help someone else


Richard
 
Richard

the better way, perhaps, is to ensure that the php code that fires on an ajax request, returns no-cache headers to the browser. or alternatively to use POST methods rather then GET. or alternatively again, add a timestamp to each GET request so that the browser distinguishes the event from previous, cached, requests.

try calling this function before you return your data via the ajax channel

Code:
function sendNoCacheHeaders(){
 //from php manual user notes
 header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
 header( 'Cache-Control: no-store, no-cache, must-revalidate' );
 header( 'Cache-Control: post-check=0, pre-check=0', false );
 header( 'Pragma: no-cache' );
}

the last option mentioned above would just involve appending a query parameter to the url that you are using

Code:
function getTimestamp(){
 var d = new Date();
 return d.getTime();
}
var url = '[URL unfurl="true"]http://www.domain.com?var1=val1&var2=val2[/URL][red]&timestamp=' + getTimestamp();

obviously, a timestamp itself is not required - any random string will suffice. if your application affects a database then you might consider using a nonce instead of a timestamp and then using the nonce to validate requests and prevent browser resubmits etc. 'nonce' is a wordpress term so for info google for 'wordpress nonce'
 
Or if you are just using AJAX rather than PHP simply add a random ID to the end of the URL that you send:
Code:
url=url+"&sid="+Math.random()

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
What a problem

Its definatly not a good idea to modify the internet options, I couldn't get on the bank website this morning & it took ages to login here and get back to this page then half the thread was missing.

Thanks for the suggestions they have been really usefull.

Richard
 
Status
Not open for further replies.

Similar threads

Replies
2
Views
71

Part and Inventory Search

Sponsor

Back
Top