. Updated Daily. Editions SDA India   SDA Indonesia
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Thursday, 8 February 2007

Use PHP to Stop IE from Caching AJAX Requests

 

 

Justin Silverton in a new post over his blog tells you about an issue which he faced while working on a AJAX Project. The issue was that through a GET request when every time he tried to call a certain function, it was returning the same data.

He tried the following code in PHP, which disables the browser caching:

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-cache, must-revalidate” );
header( “Pragma: no-cache” );


But he says the result did not change and he finally came to the following solutions.

  • use a POST request. When using with xmlhttprequest, it is slightly more complicated
  • add a unique identifier to the end of my GET URL

He chooses the second option. A unique Identifier can be created using the current data+time he says. He shows a way in the following to generate this in JavaScript:

var date = new Date();
var timestamp = date.getTime();
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleMessages;
xmlHttp.open(”GET”,”script.php?time=”+timestamp,true);
xmlHttp.send(null);

 

Read the Post

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use