<?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: Encapsulating Ajax Calls in an XHTML Friendly Way</title>
	<atom:link href="http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/</link>
	<description>code = joy</description>
	<lastBuildDate>Fri, 02 Dec 2011 01:36:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Mohit</title>
		<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/comment-page-1/#comment-6577</link>
		<dc:creator>Mohit</dc:creator>
		<pubDate>Thu, 25 Jan 2007 21:32:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=946#comment-6577</guid>
		<description>Hi

Thanks for the great approach.

I was wondering:

Can we use this approach to pass a HandlerFunction to the class and have this class call the HandlerFunction after it recives the response from the server (maybe returning an object parsed from the responseText).

Also what is the overhead (or performance bottleneck) of having multiple XMLhttp objects.

Thanks
Mohit
</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Thanks for the great approach.</p>
<p>I was wondering:</p>
<p>Can we use this approach to pass a HandlerFunction to the class and have this class call the HandlerFunction after it recives the response from the server (maybe returning an object parsed from the responseText).</p>
<p>Also what is the overhead (or performance bottleneck) of having multiple XMLhttp objects.</p>
<p>Thanks<br />
Mohit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ward Ruth</title>
		<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/comment-page-1/#comment-6576</link>
		<dc:creator>Ward Ruth</dc:creator>
		<pubDate>Tue, 07 Mar 2006 18:05:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=946#comment-6576</guid>
		<description>Mike:

Thanks for the excellent approach. I&#039;m new to Ajax etc., having been a pretty heads-down flash coder, but I&#039;m starting to branch out a little. I used your class with a little modification for my portfolio site. It worked really well.

I do think the idea of separating the responsibility for loading the XMLHTTPRequest object and rendering it are most flexibly and reusably handled by handing off the rendering to a dedicated Renderer object. This is what I did at least, and seemed to work well.

For instance, in the constructor of my WRMessageLoader I have

[code]
function WRMessageLoader( pDataURL, pRenderer, pErrorHandler ) {
	this._dataURL = pDataURL;
	this._renderer = pRenderer;
	
	if( pErrorHandler != undefined ) {
		this._errorHandler = pErrorHandler;
	}
}
[/code]

Then in my _onData method I do this (I&#039;ve used the convenience variable p for WRMessageLoader.prototype):

[code]
p._onData = function() {

	if( this._request.readyState == 4 ) {
		
		if( this._request.status == &quot;200&quot; ) {
			this._renderer.render( this._request );
		}
		else {
			this._handleError(
					{	loaderMessage:	&quot;Load Failed.&quot;,
						status:			this._request.status,
						statusText:		this._request.statusText } );	
		}
		
		delete this._request;
	}	
};
[/code]

So my renderer just implements a render() method that tackes the XMLHTTPRequest object as a parameter, and it can then use the responseText or responseXML on that depending on how it wants to render.

Here&#039;s what _handleError() does, btw:
[code]
p._handleError = function( pMessageObject ) {
	pMessageObject.source = this;
	
	if( this._errorHandler != undefined ) {
		
		if( typeof this._errorHandler == &quot;function&quot; ) {
			this._errorHandler( pMessageObject );
		}
		else {
			this._errorHandler.onError( pMessageObject );
		}
	}
};
[/code]

I also potentially call that from load():

[code]
p.load = function() {
	this._request = this._getXMLHTTPRequest();

	if( !this._request ) {
		this._handleError( { loaderMessage: &quot;Could not create HTTPRequest object.&quot; } );
		return false;
	}
	
	
	var ml = this;

	this._request.onreadystatechange = function() {
		ml._onData();
	};

	this._request.open( &quot;GET&quot;, this._dataURL, true );
	this._request.send(&quot;&quot;);
	
	return true;
};
[/code]

Thanks again Mike -- this helped quite a lot!</description>
		<content:encoded><![CDATA[<p>Mike:</p>
<p>Thanks for the excellent approach. I&#8217;m new to Ajax etc., having been a pretty heads-down flash coder, but I&#8217;m starting to branch out a little. I used your class with a little modification for my portfolio site. It worked really well.</p>
<p>I do think the idea of separating the responsibility for loading the XMLHTTPRequest object and rendering it are most flexibly and reusably handled by handing off the rendering to a dedicated Renderer object. This is what I did at least, and seemed to work well.</p>
<p>For instance, in the constructor of my WRMessageLoader I have</p>
<p>[code]<br />
function WRMessageLoader( pDataURL, pRenderer, pErrorHandler ) {<br />
	this._dataURL = pDataURL;<br />
	this._renderer = pRenderer;</p>
<p>	if( pErrorHandler != undefined ) {<br />
		this._errorHandler = pErrorHandler;<br />
	}<br />
}<br />
[/code]</p>
<p>Then in my _onData method I do this (I&#8217;ve used the convenience variable p for WRMessageLoader.prototype):</p>
<p>[code]<br />
p._onData = function() {</p>
<p>	if( this._request.readyState == 4 ) {</p>
<p>		if( this._request.status == "200" ) {<br />
			this._renderer.render( this._request );<br />
		}<br />
		else {<br />
			this._handleError(<br />
					{	loaderMessage:	"Load Failed.",<br />
						status:			this._request.status,<br />
						statusText:		this._request.statusText } );<br />
		}</p>
<p>		delete this._request;<br />
	}<br />
};<br />
[/code]</p>
<p>So my renderer just implements a render() method that tackes the XMLHTTPRequest object as a parameter, and it can then use the responseText or responseXML on that depending on how it wants to render.</p>
<p>Here&#8217;s what _handleError() does, btw:<br />
[code]<br />
p._handleError = function( pMessageObject ) {<br />
	pMessageObject.source = this;</p>
<p>	if( this._errorHandler != undefined ) {</p>
<p>		if( typeof this._errorHandler == "function" ) {<br />
			this._errorHandler( pMessageObject );<br />
		}<br />
		else {<br />
			this._errorHandler.onError( pMessageObject );<br />
		}<br />
	}<br />
};<br />
[/code]</p>
<p>I also potentially call that from load():</p>
<p>[code]<br />
p.load = function() {<br />
	this._request = this._getXMLHTTPRequest();</p>
<p>	if( !this._request ) {<br />
		this._handleError( { loaderMessage: "Could not create HTTPRequest object." } );<br />
		return false;<br />
	}</p>
<p>	var ml = this;</p>
<p>	this._request.onreadystatechange = function() {<br />
		ml._onData();<br />
	};</p>
<p>	this._request.open( "GET", this._dataURL, true );<br />
	this._request.send("");</p>
<p>	return true;<br />
};<br />
[/code]</p>
<p>Thanks again Mike &#8212; this helped quite a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike chambers</title>
		<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/comment-page-1/#comment-6575</link>
		<dc:creator>mike chambers</dc:creator>
		<pubDate>Fri, 10 Feb 2006 16:40:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=946#comment-6575</guid>
		<description>&gt;Come come Mike, what if I don&#039;t want to render html on response

Well, the same thing applies regardless of where your XMLHttpRequest object lives.

The point is, that you need to pass in a reference to the dom node that you will be appending content to.

mike chambers

mesh@adobe.com</description>
		<content:encoded><![CDATA[<p>>Come come Mike, what if I don&#8217;t want to render html on response</p>
<p>Well, the same thing applies regardless of where your XMLHttpRequest object lives.</p>
<p>The point is, that you need to pass in a reference to the dom node that you will be appending content to.</p>
<p>mike chambers</p>
<p><a href="mailto:mesh@adobe.com">mesh@adobe.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/comment-page-1/#comment-6574</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 10 Feb 2006 09:32:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=946#comment-6574</guid>
		<description>Come come Mike, what if I don&#039;t want to render html on response, a MessageLoader should have nothing to do with HTML. If you split it up properly you could even have a HTMLRenderer and a XHTMLRenderer using either innerHTML or using DOM, you could even go further and automatically use one or the other, but thats a bit out of the scope of this I feel. Also a..

var o = MessageLoader.prototype;
o.load = function(){};

etc, etc wouldn&#039;t go amiss!

Soon you&#039;ll be realising you can use your AS classes in JS and you JS classes in AS and have one single ECMA class lib, oh you&#039;ve probably changed all your AS classes to AS2, shame ;)</description>
		<content:encoded><![CDATA[<p>Come come Mike, what if I don&#8217;t want to render html on response, a MessageLoader should have nothing to do with HTML. If you split it up properly you could even have a HTMLRenderer and a XHTMLRenderer using either innerHTML or using DOM, you could even go further and automatically use one or the other, but thats a bit out of the scope of this I feel. Also a..</p>
<p>var o = MessageLoader.prototype;<br />
o.load = function(){};</p>
<p>etc, etc wouldn&#8217;t go amiss!</p>
<p>Soon you&#8217;ll be realising you can use your AS classes in JS and you JS classes in AS and have one single ECMA class lib, oh you&#8217;ve probably changed all your AS classes to AS2, shame ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff</title>
		<link>http://www.mikechambers.com/blog/2006/02/07/encapsulating-ajax-calls-in-an-xhtml-friendly-way/comment-page-1/#comment-6573</link>
		<dc:creator>Geoff</dc:creator>
		<pubDate>Tue, 07 Feb 2006 20:04:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=946#comment-6573</guid>
		<description>Is anyone actually writing *real* xhtml pages (that is, with the &#039;correct&#039; mime types and all that?

I have yet to see anyone but xhtml hobbyists (for lack of a better term) using it. If you are using xhtml 1.0 sent as text/html mime type it&#039;s perfectly fine (and probably faster, and will probably save you some kbs) to use innerHTML when writing responses.</description>
		<content:encoded><![CDATA[<p>Is anyone actually writing *real* xhtml pages (that is, with the &#8216;correct&#8217; mime types and all that?</p>
<p>I have yet to see anyone but xhtml hobbyists (for lack of a better term) using it. If you are using xhtml 1.0 sent as text/html mime type it&#8217;s perfectly fine (and probably faster, and will probably save you some kbs) to use innerHTML when writing responses.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

