Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2006, 11:17 AM
Authorized User
 
Join Date: Oct 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

append this.

var lURLToSend = "pageName.php" + "?r=" + new Date().getTime();
the getTime() method will provide an arbitrary, yet not
repeating value (milliseconds since January 1, 1970 00:00:00.000 UTC.)



Nintendo Gamecube & Revolution
http://www.gamecube-revolution.com
 
Old January 23rd, 2006, 07:06 PM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

That looks like an elegant way to handle it. Thanks.

 
Old February 2nd, 2006, 05:49 PM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts
Default

IE caches all data retrieved via XmlHttp, just to clarify what the problem is.

A server-side solution would be to set the Cache-Control header for the page, assuming you're using a server-side technology to generate the data. In C# (ASP.NET), use the Response object:

Code:
Response.CacheControl = "no-cache";
With PHP, use the header() function:

Code:
header("Cache-Control: no-cache");
It adds an extra line to your backend code, but it keeps your client-side code a bit cleaner.

------------------------
Jeremy McPeak
Author, Professional Ajax
 
Old March 2nd, 2006, 04:55 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have the same problem...

FireFox works fine if I add the following header but IE not:
header("Cache-Control: no-cache");

then I have tried adding ALSO a query string:
var lURLToSend = "pageName.php" + "?r=" + new Date().getTime();
then IE works fine and FireFox not...

:(

PHP newby
 
Old May 4th, 2006, 06:12 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same problem particulary when using ajax to perform SQL Queries, checks would stop working after x amount of rapid clicks and my
inline editing needed a shift+refresh in IE in order for it to show the correct values.

Thanks to this thread i now use both the head technique in between </BODY> and </HTML> as well as sending all my http requests with unique url's thanks to Date().Time() and it's working like a charm.

Thanks guys!

 
Old February 1st, 2007, 10:26 PM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Guys,

Here is the elegant solution you're looking for - found it on Wikipedia, of all places. I just implemented it and it works like a charm.

req.open( "GET", "xmlprovider.aspx" );
req.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
req.send( null );

http://en.wikipedia.org/wiki/Xmlhttp...r_cache_issues






Similar Threads
Thread Thread Starter Forum Replies Last Post
Recommend an AJAX IDE - JoyiStar AJAX WebShop. kingstar Ajax 4 December 15th, 2006 05:12 AM
AJAX and Browser Caches gregson09 Ajax 1 December 11th, 2006 06:44 AM
new Ajax article: Creating an Ajax Search Widget jminatel Ajax 0 May 11th, 2006 02:50 PM
New Ajax Article: Ajax Submission Throttling jminatel Ajax 0 April 11th, 2006 08:00 PM
Prevent browser from caching? itekcorp ASP.NET 1.0 and 1.1 Basics 1 October 1st, 2003 08:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.