<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Ask Dan : More on javascript threading</title>
	<atom:link href="http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/</link>
	<description>Advanced katas for javascripters</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:10:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Stuart on RefactorMyCode.com</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-369</link>
		<dc:creator>Stuart on RefactorMyCode.com</dc:creator>
		<pubDate>Mon, 10 Dec 2007 14:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-369</guid>
		<description>&lt;strong&gt;Javascript threading...&lt;/strong&gt;

Thanks for the responses ... as I said I wrote my own handler as an exercise in learning.  Probably once having done it to understand the process, I should have have switched back to a standard library.  I would never have recognised (without your help...</description>
		<content:encoded><![CDATA[<p><strong>Javascript threading&#8230;</strong></p>
<p>Thanks for the responses &#8230; as I said I wrote my own handler as an exercise in learning.  Probably once having done it to understand the process, I should have have switched back to a standard library.  I would never have recognised (without your help&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Casper on RefactorMyCode.com</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-367</link>
		<dc:creator>Casper on RefactorMyCode.com</dc:creator>
		<pubDate>Fri, 07 Dec 2007 16:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-367</guid>
		<description>&lt;strong&gt;Javascript threading...&lt;/strong&gt;

Like BK said you have global variables all over the place and this breaks the code. You have to think about what happens when your methods are called concurrently. For example &quot;console&quot; will be overwritten by the latest call, since it&#039;s a global var...</description>
		<content:encoded><![CDATA[<p><strong>Javascript threading&#8230;</strong></p>
<p>Like BK said you have global variables all over the place and this breaks the code. You have to think about what happens when your methods are called concurrently. For example &#8220;console&#8221; will be overwritten by the latest call, since it&#8217;s a global var&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BK on RefactorMyCode.com</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-366</link>
		<dc:creator>BK on RefactorMyCode.com</dc:creator>
		<pubDate>Fri, 07 Dec 2007 15:59:08 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-366</guid>
		<description>&lt;strong&gt;Javascript threading...&lt;/strong&gt;

First thing, even though you don&#039;t define the global var, since you probably didn&#039;t add var in front of xmlReq=startXMLHTTPRequest();
 it is still considered a global variable. This means that when you test readyState, you don&#039;t necessarily test th...</description>
		<content:encoded><![CDATA[<p><strong>Javascript threading&#8230;</strong></p>
<p>First thing, even though you don&#8217;t define the global var, since you probably didn&#8217;t add var in front of xmlReq=startXMLHTTPRequest();<br />
 it is still considered a global variable. This means that when you test readyState, you don&#8217;t necessarily test th&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Cooper</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-362</link>
		<dc:creator>Stuart Cooper</dc:creator>
		<pubDate>Fri, 07 Dec 2007 11:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-362</guid>
		<description>UPDATE : 
I have taken out the line 
    var xmlReq;
and it hasn&#039;t altered the behaviour.</description>
		<content:encoded><![CDATA[<p>UPDATE :<br />
I have taken out the line<br />
    var xmlReq;<br />
and it hasn&#8217;t altered the behaviour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart on RefactorMyCode.com</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-361</link>
		<dc:creator>Stuart on RefactorMyCode.com</dc:creator>
		<pubDate>Fri, 07 Dec 2007 11:09:12 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-361</guid>
		<description>&lt;strong&gt;Javascript threading...&lt;/strong&gt;

The sendRequest object.  Since reading about the global var I have tried removing the &quot;var xmlReq;&quot; line from code and there is no difference in behaviour.  The final call still gets executed while the rest stay on &quot;sending&quot;.  I can certainly see t...</description>
		<content:encoded><![CDATA[<p><strong>Javascript threading&#8230;</strong></p>
<p>The sendRequest object.  Since reading about the global var I have tried removing the &#8220;var xmlReq;&#8221; line from code and there is no difference in behaviour.  The final call still gets executed while the rest stay on &#8220;sending&#8221;.  I can certainly see t&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Cooper</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-360</link>
		<dc:creator>Stuart Cooper</dc:creator>
		<pubDate>Fri, 07 Dec 2007 10:49:10 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-360</guid>
		<description>Ask and ye shall receive!  As this was a learning exercise it may well be my xmlhttprequest that is indeed wrong.  The global variable comment triggered in my mind though as you will see below (assuming that this comment formats properly as I have a single global var.

If this is the cause I shall return to my cave happy and stop mashing my face into the keyboard.



var xmlReq;

function sendRequest(url, params, HttpMethod){

        if(!HttpMethod) {
                HttpMethod=&quot;POST&quot;;
                }

        xmlReq=startXMLHTTPRequest();

        if(xmlReq)      {

                xmlReq.onreadystatechange=onReadyState;
                xmlReq.open(HttpMethod,url,true);
                xmlReq.send(params);
        }
}


function startXMLHTTPRequest(){

        var req=null;

        try     {
                req=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
                }
                catch(e)
                {
                req=new XMLHttpRequest()
                }

        return req;

}

function onReadyState()
{
        var readyXML=xmlReq.readyState;
        var data=null;


        if(readyXML == 4){
           if(xmlReq.status == 200) {
                console.innerHTML=&#039;&#039;;
                data=xmlReq.responseText;
           }
           else {
                data=xmlReq.status;
           }
        }
        else{
                console.innerHTML=&#039;&#039;;

                if(readyXML == 3){
                        data=&quot;Serving ...&quot;;
                }
                if(readyXML == 2){
                        data=&quot;Loading ...&quot;;
                }
                if(readyXML == 1){
                        data=&quot;Sending ...&quot;;
                }
        }

        dataInnerHTML(data);
}

function dataInnerHTML(data){

        if(data!=null){
           var newline=document.createElement(&quot;div&quot;);
           console.appendChild(newline);
           newline.innerHTML+=&quot;&quot;+data+&quot;&quot;;
        }

}</description>
		<content:encoded><![CDATA[<p>Ask and ye shall receive!  As this was a learning exercise it may well be my xmlhttprequest that is indeed wrong.  The global variable comment triggered in my mind though as you will see below (assuming that this comment formats properly as I have a single global var.</p>
<p>If this is the cause I shall return to my cave happy and stop mashing my face into the keyboard.</p>
<p>var xmlReq;</p>
<p>function sendRequest(url, params, HttpMethod){</p>
<p>        if(!HttpMethod) {<br />
                HttpMethod=&#8221;POST&#8221;;<br />
                }</p>
<p>        xmlReq=startXMLHTTPRequest();</p>
<p>        if(xmlReq)      {</p>
<p>                xmlReq.onreadystatechange=onReadyState;<br />
                xmlReq.open(HttpMethod,url,true);<br />
                xmlReq.send(params);<br />
        }<br />
}</p>
<p>function startXMLHTTPRequest(){</p>
<p>        var req=null;</p>
<p>        try     {<br />
                req=new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />
                }<br />
                catch(e)<br />
                {<br />
                req=new XMLHttpRequest()<br />
                }</p>
<p>        return req;</p>
<p>}</p>
<p>function onReadyState()<br />
{<br />
        var readyXML=xmlReq.readyState;<br />
        var data=null;</p>
<p>        if(readyXML == 4){<br />
           if(xmlReq.status == 200) {<br />
                console.innerHTML=&#8221;;<br />
                data=xmlReq.responseText;<br />
           }<br />
           else {<br />
                data=xmlReq.status;<br />
           }<br />
        }<br />
        else{<br />
                console.innerHTML=&#8221;;</p>
<p>                if(readyXML == 3){<br />
                        data=&#8221;Serving &#8230;&#8221;;<br />
                }<br />
                if(readyXML == 2){<br />
                        data=&#8221;Loading &#8230;&#8221;;<br />
                }<br />
                if(readyXML == 1){<br />
                        data=&#8221;Sending &#8230;&#8221;;<br />
                }<br />
        }</p>
<p>        dataInnerHTML(data);<br />
}</p>
<p>function dataInnerHTML(data){</p>
<p>        if(data!=null){<br />
           var newline=document.createElement(&#8220;div&#8221;);<br />
           console.appendChild(newline);<br />
           newline.innerHTML+=&#8221;"+data+&#8221;";<br />
        }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Casper on RefactorMyCode.com</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/comment-page-1/#comment-175</link>
		<dc:creator>Casper on RefactorMyCode.com</dc:creator>
		<pubDate>Thu, 06 Dec 2007 16:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31#comment-175</guid>
		<description>&lt;strong&gt;Javascript threading...&lt;/strong&gt;

Are you sure you don&#039;t have a race condition sneaking in there somewhere in sendRequest()? I&#039;d like to see the implementation of that method to really make sure. No global variables or something obvious like that?
...</description>
		<content:encoded><![CDATA[<p><strong>Javascript threading&#8230;</strong></p>
<p>Are you sure you don&#8217;t have a race condition sneaking in there somewhere in sendRequest()? I&#8217;d like to see the implementation of that method to really make sure. No global variables or something obvious like that?<br />
&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
