<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SkeyMedia &#187; ie6</title>
	<atom:link href="http://skeymedia.com/tag/ie6/feed/" rel="self" type="application/rss+xml" />
	<link>http://skeymedia.com</link>
	<description>Blogging about Web Development and Website Management &#38; Monetization</description>
	<lastBuildDate>Sun, 20 Sep 2009 23:18:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>IE6 AJAX hang on readyState 3</title>
		<link>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/</link>
		<comments>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 18:10:01 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ie6]]></category>

		<guid isPermaLink="false">http://skeymedia.com/ie6-ajax-hang-on-readystate-3/</guid>
		<description><![CDATA[I recently ran into a problem that took me a few days to find a work around for. Running a basic AJAX POST, IE6 would hang up on readyState 3 for 200 seconds, throw an &#8220;Unspecified Error&#8220;, and then finally perform the action. Having a user wait 200 seconds for the IE6 timeout to come [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem that took me a few days to find a work around for.  Running a basic AJAX POST, IE6 would hang up on readyState 3 for 200 seconds, throw an &#8220;<em>Unspecified Error</em>&#8220;, and then finally perform the action.   Having a user wait 200 seconds for the IE6 timeout to come into effect is simply not a solution.  All other browsers I tested, including IE7, were not having this problem.</p>
<p>I read on the web that this may come from SSL or from compression on the webserver.   I bypassed our SSL check entirely, and it still happened.   I did not mess with the servers for http compression though.  To me, that is NOT an option to disable.   Bandwidth costs would be too much to even consider this a viable solution.</p>
<p>So, I returned to the programming aspect of it.  There has to be a code fix somewhere.</p>
<p>Long story short, IE6 doesn&#8217;t handle connection closures properly.   A typical request looks something like:</p>
<p><pre><code>
function doajax() {
var url = &quot;/script.php&quot;;
var params = &quot;x=123&amp;y=456&quot;;

//add timestamp to pass a unique param each time to prevent ie caching the ajax object
timestamp = new Date();
tim1 = (timestamp.getTime());
sec1 = timestamp.getSeconds();
ms1 = timestamp.getMilliseconds();
thetime = tim1+sec1+ms1;

params += &quot;&amp;rand=&quot;+thetime

xmlHttp.open(&#039;POST&#039;,url,true);&nbsp;&nbsp;
xmlHttp.onreadystatechange = alertContents;&nbsp;&nbsp;
xmlHttp.setRequestHeader(&quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;);
xmlHttp.setRequestHeader(&#039;If-Modified-Since&#039;,&#039;Tue, 04 Apr 2006 00:00:00 GMT&#039;);&nbsp;&nbsp;//some date in the past
xmlHttp.setRequestHeader(&quot;Content-length&quot;, params.length);
xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
}
xmlHttp.send(params);
</code></pre></p>
<p>The line in question here is<br />
<pre><code>
xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
</code></pre></p>
<p>Since this header is effectively applied for each readyState, it ends up hanging up on readyState 3.</p>
<p><strong>The easy fix:</strong><br />
Target ie6 (and other old browsers) to not close the connection.</p>
<p>change the above snippet to:<br />
<pre><code>
if(!document.all) {
&nbsp;&nbsp;xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
}
</code></pre></p>
<p>I&#8217;m not 100% sure of the implications involved in NOT closing the connection, but I haven&#8217;t seen any performance impact, and this cleared up the bug right away.  No JS errors, and no 200 second waiting.  Give it a try and let me know if it works for you as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
