<?xml version="1.0" encoding="utf-8"?><!-- generator="wordpress/2.5" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Ajax Gotchas</title>
	<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/</link>
	<description>Software, Games, Cartoons, Film, DVDs</description>
	<pubDate>Wed, 03 Dec 2008 21:23:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: jvvw</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-2866</link>
		<dc:creator>jvvw</dc:creator>
		<pubDate>Wed, 07 Jun 2006 08:48:38 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-2866</guid>
		<description>Another gotcha - don't leave any blank lines at the start of the XML file - I included a library someone else had written which did this before I started spitting out my Content-Type header and kept getting a null responseXML. As soon as I moved the Content-Type header to the top it was fine.</description>
		<content:encoded><![CDATA[<p>Another gotcha - don&#8217;t leave any blank lines at the start of the XML file - I included a library someone else had written which did this before I started spitting out my Content-Type header and kept getting a null responseXML. As soon as I moved the Content-Type header to the top it was fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fritz</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-759</link>
		<dc:creator>fritz</dc:creator>
		<pubDate>Thu, 02 Feb 2006 18:22:27 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-759</guid>
		<description>Thank you, I've been searching in JavaScript manual and AJAX references for solutions, and nothing ...

It was caching problem from the beginning, thank you guys, very much!

gg :)</description>
		<content:encoded><![CDATA[<p>Thank you, I&#8217;ve been searching in JavaScript manual and AJAX references for solutions, and nothing &#8230;</p>
<p>It was caching problem from the beginning, thank you guys, very much!</p>
<p>gg <img src='http://blog.codedread.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-744</link>
		<dc:creator>Kirk</dc:creator>
		<pubDate>Thu, 26 Jan 2006 14:42:35 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-744</guid>
		<description>Here's some code you can put in a php file to prevent caching. It solved my problem using AJAX to hit a php page:

header("ETag: PUB" . time());
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()-10) . " GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5) . " GMT");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0, max-age=1, s-maxage=1, no-cache, must-revalidate");
session_cache_limiter("nocache");</description>
		<content:encoded><![CDATA[<p>Here&#8217;s some code you can put in a php file to prevent caching. It solved my problem using AJAX to hit a php page:</p>
<p>header(&#8221;ETag: PUB&#8221; . time());<br />
header(&#8221;Last-Modified: &#8221; . gmdate(&#8221;D, d M Y H:i:s&#8221;, time()-10) . &#8221; GMT&#8221;);<br />
header(&#8221;Expires: &#8221; . gmdate(&#8221;D, d M Y H:i:s&#8221;, time() + 5) . &#8221; GMT&#8221;);<br />
header(&#8221;Pragma: no-cache&#8221;);<br />
header(&#8221;Cache-Control: post-check=0, pre-check=0, max-age=1, s-maxage=1, no-cache, must-revalidate&#8221;);<br />
session_cache_limiter(&#8221;nocache&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-526</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Thu, 22 Sep 2005 13:55:05 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-526</guid>
		<description>I tried both doing the timestamp (or randomizing) and If-Modified-Since and they both work on 1 environment. But on another development environment, it fails to retrieve the newer version of the XML file (for IE). FF works just fine (w/o the timestamp or If-Modified-Since).

I use GET to retrieve the XML file as such

http.open("GET","myfile.xml",true)

  HTTP = getHTTPObject();
  //var url = "news.xml"+"?ms="+new Date().getTime();
  var url = "news.xml";
  HTTP.open("GET",url,true);
  HTTP.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  HTTP.onreadystatechange = Process;
  HTTP.send(null);

On one server, Apache/1.2.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7e PHP/4.3.10 (as returned by 

  alert(HTTP.getAllResponseHeaders());

It still loads the initial XML file before changes were made to it.

On this server, Netscape-Enterprise/3.6 SP2, as I'm making changes to the XML file, it loads the changed XML just fine.

Any ideas? FF works fine on either servers.</description>
		<content:encoded><![CDATA[<p>I tried both doing the timestamp (or randomizing) and If-Modified-Since and they both work on 1 environment. But on another development environment, it fails to retrieve the newer version of the XML file (for IE). FF works just fine (w/o the timestamp or If-Modified-Since).</p>
<p>I use GET to retrieve the XML file as such</p>
<p>http.open(&#8221;GET&#8221;,&#8221;myfile.xml&#8221;,true)</p>
<p>  HTTP = getHTTPObject();<br />
  //var url = &#8220;news.xml&#8221;+&#8221;?ms=&#8221;+new Date().getTime();<br />
  var url = &#8220;news.xml&#8221;;<br />
  HTTP.open(&#8221;GET&#8221;,url,true);<br />
  HTTP.setRequestHeader(&#8217;If-Modified-Since&#8217;, &#8216;Sat, 1 Jan 2000 00:00:00 GMT&#8217;);<br />
  HTTP.onreadystatechange = Process;<br />
  HTTP.send(null);</p>
<p>On one server, Apache/1.2.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7e PHP/4.3.10 (as returned by </p>
<p>  alert(HTTP.getAllResponseHeaders());</p>
<p>It still loads the initial XML file before changes were made to it.</p>
<p>On this server, Netscape-Enterprise/3.6 SP2, as I&#8217;m making changes to the XML file, it loads the changed XML just fine.</p>
<p>Any ideas? FF works fine on either servers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glan Thomas</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-436</link>
		<dc:creator>Glan Thomas</dc:creator>
		<pubDate>Tue, 23 Aug 2005 16:34:49 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-436</guid>
		<description>I noticed this problem too, only that IE on windoz once it loaded content once would never load it again. I got round this by adding a random number at the end of the url after '?'. Its well cowboy work-around, coding for IE5.5 and 6 is ever more difficult since it like 4 years behind everyone else.</description>
		<content:encoded><![CDATA[<p>I noticed this problem too, only that IE on windoz once it loaded content once would never load it again. I got round this by adding a random number at the end of the url after &#8216;?&#8217;. Its well cowboy work-around, coding for IE5.5 and 6 is ever more difficult since it like 4 years behind everyone else.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Vogt</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-432</link>
		<dc:creator>Jason Vogt</dc:creator>
		<pubDate>Sun, 21 Aug 2005 06:10:04 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-432</guid>
		<description>This is a technique I used to get around the caching problem. It is the most elegant solution I found.


ajaxRequest.open("GET", url, true);

// This ensures that the result is not cached.
ajaxRequest.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );

ajaxRequest.send(null);</description>
		<content:encoded><![CDATA[<p>This is a technique I used to get around the caching problem. It is the most elegant solution I found.</p>
<p>ajaxRequest.open(&#8221;GET&#8221;, url, true);</p>
<p>// This ensures that the result is not cached.<br />
ajaxRequest.setRequestHeader( &#8220;If-Modified-Since&#8221;, &#8220;Sat, 1 Jan 2000 00:00:00 GMT&#8221; );</p>
<p>ajaxRequest.send(null);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-430</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Fri, 19 Aug 2005 23:10:50 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-430</guid>
		<description>I believe "idempotent" is supposed to mean that the side effects of repeated requests are identical to the side effects of one request.  Note that this is in regards to "side effects", not to "response" or "output".

POST is supposed to be used to denote making a durable change in a resource of some kind.

The real issue is caching, and I think IE has never handled caching very well.  (Note: I believe using SSL generally disables caching.  Although it increases the bandwidth and computational requirements, it also keeps your transactions away from prying eyes.)</description>
		<content:encoded><![CDATA[<p>I believe &#8220;idempotent&#8221; is supposed to mean that the side effects of repeated requests are identical to the side effects of one request.  Note that this is in regards to &#8220;side effects&#8221;, not to &#8220;response&#8221; or &#8220;output&#8221;.</p>
<p>POST is supposed to be used to denote making a durable change in a resource of some kind.</p>
<p>The real issue is caching, and I think IE has never handled caching very well.  (Note: I believe using SSL generally disables caching.  Although it increases the bandwidth and computational requirements, it also keeps your transactions away from prying eyes.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim d</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-429</link>
		<dc:creator>Jim d</dc:creator>
		<pubDate>Fri, 19 Aug 2005 22:30:48 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-429</guid>
		<description>"... I have no idea if this should be considered a bug from the IE side or the FF side..."

It shouldn't be considered a bug at all.  You're telling the server to send a GET request.  According to the W3 spec,  GET requests are "idempotent", meaning that the repeated requests with identical   input yield identical output.   This is why browsers and firewalls cache these types of requests.

You can get around problems entirely if you use POST instead of GET.  Most of the time you really want POST anyway.   Just change your code like so..

    req.open(”POST”, urlstr, true);  //Mission accomplised.

Yes, you can certainly use tricks  to fool the browser into downloading a new copy for a GET request.  However, probably shouldn't be doing this depending on your intended goal.</description>
		<content:encoded><![CDATA[<p>&#8220;&#8230; I have no idea if this should be considered a bug from the IE side or the FF side&#8230;&#8221;</p>
<p>It shouldn&#8217;t be considered a bug at all.  You&#8217;re telling the server to send a GET request.  According to the W3 spec,  GET requests are &#8220;idempotent&#8221;, meaning that the repeated requests with identical   input yield identical output.   This is why browsers and firewalls cache these types of requests.</p>
<p>You can get around problems entirely if you use POST instead of GET.  Most of the time you really want POST anyway.   Just change your code like so..</p>
<p>    req.open(”POST”, urlstr, true);  //Mission accomplised.</p>
<p>Yes, you can certainly use tricks  to fool the browser into downloading a new copy for a GET request.  However, probably shouldn&#8217;t be doing this depending on your intended goal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-428</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Fri, 19 Aug 2005 21:45:10 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-428</guid>
		<description>Are you sure you can't set another header on the PHP side to disable caching?  Read the header docs at http://us2.php.net/header

</description>
		<content:encoded><![CDATA[<p>Are you sure you can&#8217;t set another header on the PHP side to disable caching?  Read the header docs at <a href="http://us2.php.net/header" rel="nofollow">http://us2.php.net/header</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-415</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 09 Aug 2005 19:07:08 +0000</pubDate>
		<guid>http://blog.codedread.com/archives/2005/04/21/ajax-gotchas/#comment-415</guid>
		<description>Agreed that it is unlikely, but I like your tip of using the timestamp instead of a random string...</description>
		<content:encoded><![CDATA[<p>Agreed that it is unlikely, but I like your tip of using the timestamp instead of a random string&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
