<?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>Web Dev Bros &#187; JSON</title>
	<atom:link href="http://www.webdevbros.net/category/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Thu, 20 Jan 2011 19:55:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ASP JSON utility version 1.5 released</title>
		<link>http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/</link>
		<comments>http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 14:17:40 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=183</guid>
		<description><![CDATA[Its long time ago since there has been an update to the JSON utility class. Thats because its working very stable thanks to your support! Nevertheless we have a new version with new features and some minor bugfixes. The following has been updated: 0. Bugfixes When a dictionary contained no items then nothing was returned [...]]]></description>
			<content:encoded><![CDATA[<p>Its long time ago since there has been an update to the <a href="http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/">JSON utility class</a>. Thats because its working very stable thanks to your support! Nevertheless we have a new version with new features and some minor bugfixes. The following has been updated:<span id="more-183"></span></p>
<p><strong>0. Bugfixes</strong></p>
<ul>
<li>When a dictionary contained no items then nothing was returned (<code>"someDict":{}</code>). According to the JSON RFC this is not correct and results in invalid JSON. It returns null now. <code>"someDict": null</code></li>
<li>The class supposed to fully support UTF-8 but it didnt 100%. e.g. chinese chars wouldnt work at all. This has been solved and works perfectly now!! Thanks to Jef Housein for his help and we welcome all asian asp developer now ;)</li>
</ul>
<p><strong>1. toJSON() method is default now</strong></p>
<p>This is a minor improvement but makes our client code much nicer. See the difference:</p>
<div class="igBar"><span id="lasp-5"><a href="#" onclick="javascript:showCodeTxt('asp-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-5">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'before</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">output = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"root"</span>, <span style="color:#CC0000;">"some value"</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'now additionally possible:</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">output = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"root"</span>, <span style="color:#CC0000;">"some value"</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> </p>
<p><strong>2. supports ASP request object</strong></p>
<p>Thanks to <a href="http://www.cment.net">Jeremy Brown</a> who inspired me with his extension to support the ASP's <code>request</code> object. Therefore its possible now to represent the whole request object in JSON format. It includes <code>request.form, request.cookies, request.servervariables</code>, etc. (check its properties at <a href="http://www.w3schools.com/ASP/asp_ref_request.asp">w3schools</a>). Simple example of how to access the <code>HTTP_HOST</code> server variable within javascript:</p>
<div class="igBar"><span id="lasp-6"><a href="#" onclick="javascript:showCodeTxt('asp-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-6">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span>empty, <span style="color:#990099; font-weight:bold;">request</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#330066;">servervariables</span>.<span style="color:#9900CC;">HTTP_HOST</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Yeah, new default method already in use :)<br />
Note: All properties of the request object are exposed in lowercase (such as <code>servervariables, form</code>, ...). Because of this extension the class also supports the <code>IStringList</code> and <code>IRequestDictionary</code> types now as well. Oh vtw, with this we can also easily access the users session from client side if neccesary:</p>
<div class="igBar"><span id="lasp-7"><a href="#" onclick="javascript:showCodeTxt('asp-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-7">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span>empty, <span style="color:#990099; font-weight:bold;">request</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#990099; font-weight:bold;">session</span>.<span style="color:#9900CC;">some_session_var</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>3. Using paged recordsets</strong></p>
<p>Till now all records of both dynamic &#038; staic recordsets have been returned. What if you are using a paged recordset (<code>recordset.pageSize</code> property)? its very likely that you only want those records of the current page. Thanks to <a href="javascript:alert('dont know his website :(')">Jef Housein</a> this is possible now, but its functionality has to be turned on with the new <code>recordsetPaging</code> property. By default this behaivour so it does not break existing apps ;) Using a paged recordset would work like this:</p>
<div class="igBar"><span id="lasp-8"><a href="#" onclick="javascript:showCodeTxt('asp-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-8">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> j = <span style="color:#0000FF; font-weight:bold;">new</span> JSON</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">j.<span style="color:#9900CC;">recordsetPaging</span> = <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> RS = <span style="color:#990099; font-weight:bold;">server</span>.<span style="color:#330066;">createObject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"ADODB.recordset"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RS.<span style="color:#9900CC;">pageSize</span> = <span style="color:#800000;color:#800000;">5</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'... and executing some command</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">output = j<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"root"</span>, RS, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'output would always hold max. 5 records of RS now </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>4. Updated documentation</strong></p>
<p>Documentation of the class has been heavily updated. Code examples have been added and most of the docs has been reviewed. <a href='http://www.webdevbros.net/wp-content/uploads/2008/07/jsondoc.html'>Click here to see the updated doc.</a></p>
<p><strong><a href='http://www.webdevbros.net/wp-content/uploads/2008/07/json151.zip'>Download JSON utility class 1.5.1</a></strong><br />
<a href='http://www.webdevbros.net/wp-content/uploads/2008/07/json15.zip'>Download JSON utility class 1.5</a><br />
(no changes needed when upgrading from 1.4)</p>
<p><strong>Update 15.07.2008:</strong> v1.5 contained a bug when generating empty dictionaries (see james comment). v1.5.1 has fixed this. Thanks James!</p>
<p>Thanks a lot for all who helped making this little tool what it is. Dont forget that it is a major component within the <a href="http://www.webdevbros.net/ajaxed">ajaxed library</a>. Using ajaxed makes your life even more easier ....</p>
<p>Greetings from hong kong!</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/&amp;t=ASP+JSON+utility+version+1.5+released&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/&amp;title=ASP+JSON+utility+version+1.5+released&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/&amp;title=ASP+JSON+utility+version+1.5+released&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=ASP+JSON+utility+version+1.5+released;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ASP JSON utility class 1.4 released</title>
		<link>http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/</link>
		<comments>http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 18:10:00 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/</guid>
		<description><![CDATA[I did check all your comments on the JSON utility class and fixed the existing bugs. The new changes are available in version 1.4 which is available for download now. I really appreciate your help by posting your comments and solutions. Most of them have been considered in the new version. Have fun and please [...]]]></description>
			<content:encoded><![CDATA[<p>I did check all your comments on the <a href="http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/">JSON utility class</a> and fixed the existing bugs. The new changes are available in version 1.4 which is available for download now. I really appreciate your help by posting your comments and solutions. Most of them have been considered in the new version.  Have fun and please keep me informed about new issues.</p>
<p><a href='http://www.webdevbros.net/wp-content/uploads/2007/12/json14.zip' title='JSON 1.4'>Download JSON 1.4</a></p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/&amp;t=ASP+JSON+utility+class+1.4+released&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/&amp;title=ASP+JSON+utility+class+1.4+released&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/&amp;title=ASP+JSON+utility+class+1.4+released&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=ASP+JSON+utility+class+1.4+released;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/18/asp-json-utility-class-14-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JSON Utility class 1.3 released</title>
		<link>http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/</link>
		<comments>http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 14:59:22 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/</guid>
		<description><![CDATA[The summer here in Austria is really hot this year and therefore I had not much time to do a lot for webdevbros. Enjoying the sun as much as possible ;) However I was very happy about getting a big amount of feedback for my JSON utility class which showed me that you guys out [...]]]></description>
			<content:encoded><![CDATA[<p>The summer here in Austria is really hot this year and therefore I had not much time to do a lot for webdevbros. Enjoying the sun as much as possible ;) However I was very happy about getting a big amount of feedback for my JSON utility class which showed me that you guys out there are using it. Thanks for that! As a gift for that I spent some time to update the class and released a <a href="/2007/04/26/generate-json-from-asp-datatypes/"><strong>1.3 version</strong></a>. Changes are the following:</p>
<ul>
<li>The class can easily be used with "Option Explicit" now</li>
<li>Multidimensional arrays are supported (unlimited dimensions)</li>
</ul>
<p><a href="/2007/04/26/generate-json-from-asp-datatypes/">Go to the download</a> and grab your version. It is backwards compatible so it is not a problem to override your old version .. hopefully you didnt change anything ;). Have fun with it and feedback is welcomed. </p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/&amp;t=JSON+Utility+class+1.3+released&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/&amp;title=JSON+Utility+class+1.3+released&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/&amp;title=JSON+Utility+class+1.3+released&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=JSON+Utility+class+1.3+released;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/08/21/json-utility-class-13-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ajaxed: Calling server side VBScript procedures from client side (equivalent to PHP xajax)</title>
		<link>http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/</link>
		<comments>http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/#comments</comments>
		<pubDate>Sun, 01 Jul 2007 23:50:56 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajaxed]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>
		<category><![CDATA[protoypejs]]></category>
		<category><![CDATA[xajax]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/</guid>
		<description><![CDATA[My last post (about an ASP RSS component) included a demonstration which made use of a cool ajax technique simply called "ajaxed". See the demonstration here again. If you play around you will recognize that there is no conventional postback and AJAX is up in here ;) I have developed a small "library" which easily [...]]]></description>
			<content:encoded><![CDATA[<p>My last post (about an ASP RSS component) included a demonstration which made use of a cool ajax technique simply called "ajaxed". <a href="http://www.grafix.at/webdevbros/RSS" target="_blank">See the demonstration here again.</a> If you play around you will recognize that there is no conventional postback and AJAX is up in here ;) I have developed a small "library" which easily allows you to call server side ASP VBScrtipt procedures from the client side. No low-level Ajax knowledge is required...<span id="more-78"></span><br />
Summarized it can be said that I have developed a bit similar thing for ASP like there is already for PHP (xajax - <a href="http://www.xajaxproject.org/">http://www.xajaxproject.org/</a>). It is not the same as xajax but it also allows you to call server side procedures from client side. We are all tired of the conventional postbacks which refresh the whole page, thats why we want ajax. I was tired of hacking all the lowlevel stuff for ajax and thought of a way to call the ASP procedures directly. With this and some stuff of my existing gabLibrary I have built a small library called "ajaxed". ajaxed just because it makes my pages ajaxed. Here is a very simple example which sums up two numbers (<a href="http://www.grafix.at/ajaxed/demo.asp" target="_blank">Try the demo here</a>):</p>
<div class="igBar"><span id="lasp-13"><a href="#" onclick="javascript:showCodeTxt('asp-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-13">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;!--#include virtual=<span style="color:#CC0000;">"/ajaxed/ajaxed.asp"</span>--&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> page = <span style="color:#0000FF; font-weight:bold;">new</span> AjaxedPage</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">page.<span style="color:#9900CC;">draw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> callback<span style="color:#006600; font-weight:bold;">&#40;</span>action<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> action = <span style="color:#CC0000;">"add"</span> <span style="color:#990099; font-weight:bold;">then</span> page.<span style="color:#9900CC;">return</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#330066;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>page.<span style="color:#9900CC;">RF</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"a"</span><span style="color:#006600; font-weight:bold;">&#41;</span>, page.<span style="color:#9900CC;">RF</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"b"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">function</span> <span style="color:#330066;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>a, b<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">not</span> <span style="color:#990099; font-weight:bold;">isnumeric</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span> a = <span style="color:#800000;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">not</span> <span style="color:#990099; font-weight:bold;">isnumeric</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span> b = <span style="color:#800000;color:#800000;">0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#330066;">add</span> = <span style="color:#990099; font-weight:bold;">cint</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color:#990099; font-weight:bold;">cint</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> main<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;script&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">function</span> added<span style="color:#006600; font-weight:bold;">&#40;</span>sum<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#008000;">'c').value = sum;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;form id=<span style="color:#CC0000;">"frm"</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span style="color:#CC0000;">"Text"</span> name=<span style="color:#CC0000;">"a"</span> id=<span style="color:#CC0000;">"a"</span>&gt;+</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span style="color:#CC0000;">"Text"</span> name=<span style="color:#CC0000;">"b"</span> id=<span style="color:#CC0000;">"b"</span>&gt;=</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span style="color:#CC0000;">"Text"</span> name=<span style="color:#CC0000;">"c"</span> id=<span style="color:#CC0000;">"c"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;button onclick=<span style="color:#CC0000;">"ajaxed.callback('add', added)"</span> type=<span style="color:#CC0000;">"button"</span>&gt;calculate&lt;/button&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;/form&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span> <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>At first sight you can see that the calculation is done on server side ("add" function) and there is no classical XHR and not much JavaScript. The calculation is invoked through the button and therefore the button includes a JavaScript call which defines the "gateway" to the server side. Before I explain how the execution works, it is necessary to look at the page structure. The structure of an ajaxed page (as shown in the example) is the following:</p>
<ol>
<li>Loading ajaxed.asp (include)</li>
<li>Create an instance of the AjaxedPage class and execute draw()</li>
<li>Provide 3 methods:
<ol>
<li>init(): executed on every request (before main() or callback())</li>
<li>main(): executed when the page is ordinary called by a user</li>
<li>callback(): executed when the page calls itself again and requests a server side method (action)</li>
</ol>
</li>
</ol>
<p>The execution flow results as followed:</p>
<ol>
<li>init()</li>
<li>main() or callback()</li>
</ol>
<p>The whole trick here is that the page is able to make a request to itself. It has two states. One for the ordinary request of the user - which normally displays the user interface with (X)HTML. The other state is when the page requests itself again - which results in a JSON response. Ok lets forget the underlying technical details now...</p>
<p>The entry point in the example is the draw() method which draws the page and cares about everything for you. As already mentioned you need to provide the procedures init(), main() and a callback(action) in your page. Whereas init() is executed on every request the main() and callback() are never executed togehter. All the presentation should be put in the main() - you see the form in the example is in the main(). All security checks, preperations, initializations, etc should be put into the init() which is always executed before the main() and callback(action). When is the callback called? It is called if the ajaxed.callback JavaScript function is executed - which in this case is in the onclick event of the button. The ajaxed.callback requires an action (which is used as input for the server side callback function) and a JavaScript callback function which will be called after the server side process has been finished. This callback function (added) gets then the return of the server side function call. In this case with page.return(). The nice thing is that the page handles all conversions from the VBScript datatypes into the JavaScript equivalents (see <a href="/2007/04/26/generate-json-from-asp-datatypes">Generate JSON from ASP datatypes</a> if you are interested in the details). The page posts all form variables by default to the callback which means that the form fields are accessible via request.form within the callback. The AjaxedPage class offers several convenient utility methods to access the request collection. If you dont want to post the whole form or use your own parameters for the callback, you can use the third parameter of the ajaxed.callback function (with JSON). E.g.</p>
<div class="igBar"><span id="ljavascript-14"><a href="#" onclick="javascript:showCodeTxt('javascript-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-14">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ajaxed.<span style="color: #006600;">callback</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'serversideAction'</span>, jsCallback, <span style="color: #66cc66;">&#123;</span>param1:<span style="color: #CC0000;color:#800000;">1</span>, param2:<span style="color: #3366CC;">'michal'</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>With this technique its now possible to call all your server side procedures and then change the DOM according to the return value(s) from the server side. There is no need to care about any XHR or e.g. loading indication. Everything is handled. Another example?</p>
<p><strong>Populating dropdown from the database</strong></p>
<p>Lets assume we have a table called "table" which holds two columns named "id" and "name". We want to fill a dropdown with those values. id as the value and name as the displayed text. I have created a form which holds dropdown and a button. The button invokes the database call on server side. The callback then returns an ADODB.recordset which is automatically converted into an equivalent JavaScript data structure. The "got" JavaScript function can directly access the recordsets data. (Note: the "getRecordset" function does not exist and is just for demonstration)</p>
<div class="igBar"><span id="lasp-15"><a href="#" onclick="javascript:showCodeTxt('asp-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-15">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;!--#include virtual=<span style="color:#CC0000;">"/ajaxed/ajaxed.asp"</span>--&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> page = <span style="color:#0000FF; font-weight:bold;">new</span> AjaxedPage</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">page.<span style="color:#9900CC;">draw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> callback<span style="color:#006600; font-weight:bold;">&#40;</span>action<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> action = <span style="color:#CC0000;">"get"</span> <span style="color:#990099; font-weight:bold;">then</span> page.<span style="color:#9900CC;">return</span><span style="color:#006600; font-weight:bold;">&#40;</span>getRecordset<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"SELECT * FROM table"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> main<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;script&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">function</span> got<span style="color:#006600; font-weight:bold;">&#40;</span>recs<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span>i = <span style="color:#800000;color:#800000;">0</span>; i &lt;recs.<span style="color:#9900CC;">length</span>; i++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">var</span> o = <span style="color:#0000FF; font-weight:bold;">new</span> <span style="color:#0000FF; font-weight:bold;">Option</span><span style="color:#006600; font-weight:bold;">&#40;</span>recs<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">name</span>, recs<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">id</span>, <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#008000;">'dd').options[$('dd').options.length] = o;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;form id=<span style="color:#CC0000;">"frm"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;select id=<span style="color:#CC0000;">"dd"</span>&gt;&lt;/select&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;button onclick=<span style="color:#CC0000;">"ajaxed.callback('get', got)"</span> type=<span style="color:#CC0000;">"button"</span>&gt;load&lt;/button&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;/form&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span> <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Returning more values with returnValue()</strong></p>
<p>The following example demonstrates that it is also possible to return more values on the callback. returnValue() allows to return more values by specifying each value with a name. return() in comparision can only return one value.</p>
<p><a href="http://www.grafix.at/webdevbros/ajaxed2.asp">Run the example</a></p>
<p>(It expects some value in the textbox. if no value is given then a "valid" flag is set to false and returned from server side. If some input is provided then an array additionally to the valid flag is returned. This example make not much sense but demonstrates the usage of more return values)</p>
<div class="igBar"><span id="lasp-16"><a href="#" onclick="javascript:showCodeTxt('asp-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-16">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;!--#include virtual=<span style="color:#CC0000;">"/ajaxed/ajaxed.asp"</span>--&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> page = <span style="color:#0000FF; font-weight:bold;">new</span> AjaxedPage</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">page.<span style="color:#9900CC;">draw</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> callback<span style="color:#006600; font-weight:bold;">&#40;</span>action<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> action = <span style="color:#CC0000;">"do"</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color:#9900CC;">returnValue</span> <span style="color:#CC0000;">"valid"</span>, page.<span style="color:#9900CC;">RFHas</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"code"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> page.<span style="color:#9900CC;">RFHas</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"code"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color:#9900CC;">returnValue</span> <span style="color:#CC0000;">"even"</span>, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">4</span>, <span style="color:#800000;color:#800000;">6</span>, <span style="color:#800000;color:#800000;">8</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">sub</span> main<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">function</span> done<span style="color:#006600; font-weight:bold;">&#40;</span>r<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>r.<span style="color:#9900CC;">valid</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span>i = <span style="color:#800000;color:#800000;">0</span>; i &lt;r.<span style="color:#9900CC;">even</span>.<span style="color:#9900CC;">length</span>; i++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#008000;">'vals').innerHTML += r.even[i] + &quot;&lt;br&gt;&quot;;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#990099; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"type in something!"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;form id=<span style="color:#CC0000;">"frm"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=<span style="color:#CC0000;">"vals"</span>&gt;&lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span style="color:#CC0000;">"Text"</span> name=<span style="color:#CC0000;">"code"</span> <span style="color:#330066;">value</span>=<span style="color:#CC0000;">""</span>&gt; <span style="color:#006600; font-weight:bold;">&#40;</span>type <span style="color:#990099; font-weight:bold;">in</span> something<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;button onclick=<span style="color:#CC0000;">"ajaxed.callback('do', done)"</span> type=<span style="color:#CC0000;">"button"</span>&gt;load&lt;/button&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;/form&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span> <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">sub</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The concept makes use of <a href="www.prototypejs.org">Prototype JavaScript Library</a> and the <a href="/2007/04/26/generate-json-from-asp-datatypes">JSON utility class</a>.<br />
The ajaxed library includes those and therefore they can be used when working with ajaxed e.g. all features of Prototype. Furthermore it offers other convenient built-in features to ease the work with ASP pages (e.g. RFHas() method in the example above - it checks if agiven field from the request.form collection exists). Some other features of the Ajaxed page ...</p>
<ul>
<li>AjaxedPage.isPostback() - equivalent to asp.net postback</li>
<li>AjaxedPage.throwError() - generates an ASP user error</li>
<li>AjaxedPage.RFT() - gets a field from the request collection already trimmed</li>
<li>AjaxedPage.RFE() - gets a field from the request collection HTMLEncoded</li>
<li>AjaxedPage.loadJSFile() - ensures that JavaScript file is loaded only once</li>
<li>AjaxedPage.iif() - an VBScript inline if</li>
<li>AjaxedPage.getLocation() - gets the location of the page in several formats</li>
</ul>
<p><a href='/wp-content/uploads/2007/07/ajaxed01.zip' title='ajaxed 0.1'>Download ajaxed 0.1</a><br />
<a href='http://www.grafix.at/ajaxed/' title='ajaxed 0.1'>ajaxed 0.1 class reference</a></p>
<p><strong>Installation</strong></p>
<p>Download the zip archive and copy the whole "ajaxed" folder into your web root. Access the demo at  http://yourserver.com/ajaxed/demo/index.asp and check if everything works fine. There is a config.asp which provides some configurations.</p>
<p>Tell me what you think about it. I will come up with some more sophisticated examples in the future. cheeers...</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/&amp;t=ajaxed%3A+Calling+server+side+VBScript+procedures+from+client+side+%28equivalent+to+PHP+xajax%29&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/&amp;title=ajaxed%3A+Calling+server+side+VBScript+procedures+from+client+side+%28equivalent+to+PHP+xajax%29&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/&amp;title=ajaxed%3A+Calling+server+side+VBScript+procedures+from+client+side+%28equivalent+to+PHP+xajax%29&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=ajaxed%3A+Calling+server+side+VBScript+procedures+from+client+side+%28equivalent+to+PHP+xajax%29;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/07/02/ajaxed-calling-server-side-vbscript-procedures-from-client-side-equivalent-to-php-xajax/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Generate JSON from VBScript (ASP) datatypes</title>
		<link>http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/</link>
		<comments>http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 16:18:26 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajaxed]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>

		<guid isPermaLink="false">http://fabiankoehler.de/wdb/2007/04/26/generate-json-from-asp-datatypes/</guid>
		<description><![CDATA[When working with JSON it's nice to have a generator for your language which transforms all the datatypes from your chosen programming language into the JSON grammar so that you can use them within javascript. For a lot of popular languages it's done already (i suppose) but I haven't found one for classic ASP .. [...]]]></description>
			<content:encoded><![CDATA[<p>When working with JSON it's nice to have a generator for your language which transforms all the datatypes from your chosen programming language into the JSON grammar so that you can use them within javascript. For a lot of popular languages it's done already (i suppose) but I haven't found one for classic ASP .. so here it comes. The following example quickly demonstrates what the goal is:</p>
<div class="igBar"><span id="lasp-25"><a href="#" onclick="javascript:showCodeTxt('asp-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-25">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> RS = getRecordset<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"SELECT * FROM table"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">response</span>.<span style="color:#330066;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"rows"</span>, RS<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>A simple usage of JSON normally is that you create a page which outputs data as JSON as the only response. This page is called later from another page and the returned data is used within a javascript function (known as callback). So the snippet above gets some data from the database and stores it in an adodb.recordset which is passed then to the JSON generator and the result is printed on the page. The consuming page would like to access the data now as it originally was within the recordset. like this:</p>
<div class="igBar"><span id="ljavascript-26"><a href="#" onclick="javascript:showCodeTxt('javascript-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-26">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> callback<span style="color: #66cc66;">&#40;</span>rows<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>i = <span style="color: #CC0000;color:#800000;">0</span>; i &lt;rows.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>rows<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">columName</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>read on to get the details...<span id="more-35"></span></p>
<p>If you are already impressed by the short example then you will save a lot of time from now on when working with JSON. I have written a class which handles the whole conversation of classic ASP datatypes to JSON grammar. In particular an ASP boolean is recognized as a boolean within javascript, an integer as a number, an array as an array, a recordset as collection, etc. I will come back to the first example later but first another example:</p>
<div class="igBar"><span id="lasp-27"><a href="#" onclick="javascript:showCodeTxt('asp-27'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-27">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"foo"</span>, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#800000;color:#800000;">1</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#9900CC;">foo</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This short snippet displays an alert with true. As you can see we passed an ASP variable which has been recognized later by javascript. In this very example we even pass an array with 3 different datatypes (boolean, int and string). Those are all accessible within javascript.</p>
<p>Even nesting is fully supported. So array within arrays, dictionaries within arrays and vice versa. Mixing is allowed in every way you imagine. This example demonstrates what i am talking about:</p>
<div class="igBar"><span id="lasp-28"><a href="#" onclick="javascript:showCodeTxt('asp-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-28">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> d = <span style="color:#990099; font-weight:bold;">server</span>.<span style="color:#330066;">createObject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"scripting.dictionary"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">d.<span style="color:#330066;">add</span> <span style="color:#CC0000;">"en"</span>, <span style="color:#CC0000;">"sausage"</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">d.<span style="color:#330066;">add</span> <span style="color:#CC0000;">"de"</span>, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"egal"</span>, <span style="color:#CC0000;">"wurst"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">%&gt;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"foo"</span>, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span>d<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#9900CC;">foo</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">de</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>We've created a dictionary (which consists of two value pairs - one holds just a string (sausage) and the other an array (egal, wurst)) and we've added this into another array which is the value of "foo". After toJSON has generated the JSON string we can access the whole structure and the alertbox says "wurst".</p>
<p>Now back to the example of the introduction. We can even pass whole recordsets to the generator which will generate a datastructure as followed:</p>
<p><strong>JSON representation for ADODB.recordset</strong></p>
<p>a recordset with two columns ID and LASTNAME will be converted into a javascript array where each field represents a row in the field and the row provides properties which are named the same as the columns within the recordset. That means that iterating through data within javascript is not a mission anymore ... look at this example:</p>
<div class="igBar"><span id="lasp-29"><a href="#" onclick="javascript:showCodeTxt('asp-29'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-29">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"data"</span>, getRecordset<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"SELECT id, lastname FROM table"</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#9900CC;">data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">lastname</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>We transfered the whole adodb.recordset from ASP to javascript using JSON. How cool is that!? </p>
<p><strong>Custom classes</strong></p>
<p>If you create your own classes within VBScript then you might like the automatic conversion of your objects into a JSON representation. As VBScript does not support introspection (reflection) it is necessary to built an own work around. If you want the JSON class to recognize your custom objects it is necessary to implement a reflect() method within the custom type. reflect() must return a dictionary with all properties where each key is the property name and the value is its value. Values can be all kind of types (because its resolved recursively anyway). The following example shows a "Person" class which implements reflect() and therefore can be used within the JSON generator:</p>
<div class="igBar"><span id="lasp-30"><a href="#" onclick="javascript:showCodeTxt('asp-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-30">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">class</span> Person</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">public</span> firstname&nbsp; &nbsp; <span style="color:#008000;">''[string] firstname</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">public</span> lastname&nbsp;<span style="color:#008000;">''[string] lastname</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">public</span> favNumbers&nbsp; &nbsp;<span style="color:#008000;">''[array] persons favorite numbers</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">public</span> <span style="color:#0000FF; font-weight:bold;">function</span> reflect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">set</span> reflect = <span style="color:#990099; font-weight:bold;">server</span>.<span style="color:#330066;">createObject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"scripting.dictionary"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">with</span> reflect</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color:#330066;">add</span> <span style="color:#CC0000;">"firstname"</span>, firstname</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color:#330066;">add</span> <span style="color:#CC0000;">"lastname"</span>, lastname</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color:#330066;">add</span> <span style="color:#CC0000;">"favNumbers"</span>, favNumbers</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">with</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">class</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The following example access the properties of the VBScript Person class within JavaScript (as it would be a JavaScript object).</p>
<div class="igBar"><span id="lasp-31"><a href="#" onclick="javascript:showCodeTxt('asp-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-31">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;%</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">set</span> p = <span style="color:#0000FF; font-weight:bold;">new</span> Person</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">p.<span style="color:#9900CC;">firstname</span> = <span style="color:#CC0000;">"John"</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">p.<span style="color:#9900CC;">lastname</span> = <span style="color:#CC0000;">"Doe"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">p.<span style="color:#9900CC;">favNumbers</span> = <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">7</span>, <span style="color:#800000;color:#800000;">234</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">%&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"p"</span>, p, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#9900CC;">p</span>.<span style="color:#9900CC;">favNumbers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Update 10.07.2008:</strong> as the <code>toJSON()</code> method has been defined as default method it can be used much quicker by leaving the methodname out:</p>
<div class="igBar"><span id="lasp-32"><a href="#" onclick="javascript:showCodeTxt('asp-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-32">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">&lt;%</span>= <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">new</span> JSON<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"root"</span>, <span style="color:#CC0000;">"some value"</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">%&gt;</span>.<span style="color:#9900CC;">root</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Those examples are really straight forward and should just demonstrate how to use the generator. Normally you don't really deal with that as a client, you'd rather have some nice classes which do all this stuff for you. In another article I will demonstrate how to combine ASP, JSON and AJAX in a nice and effective way...</p>
<p>The download of the class is at the bottom. Here is a list of the features..</p>
<ul>
<li>Transforms various datatypes from ASP to Javascript using JSON</li>
<li>Escapes all characters which needs to be escaped according to JSON's RFC</li>
<li>Recursively inspects the values so nesting of values is supported</li>
<li>Results can be returned or (for better performance) written directly to the response</li>
</ul>
<p>Have fun with it. There are other article related to this topic which might be interested for you:</p>
<ul>
<li><a href="/2007/04/26/json-character-escaping-function-in-classic-asp">JSON character escaping function in classic ASP</a></il>
<li><a href="/category/classic-asp/ajaxed/">ajaxed Library - calling server side ASP code directly from client side.</a></li>
</ul>
<p><strong>Download latest JSON ASP utility class:</strong><br />
<a href="http://www.webdevbros.net/wp-content/uploads/2008/07/json151.zip">JSON 1.5.1</a> (<a href='http://www.webdevbros.net/wp-content/uploads/2008/07/jsondoc.html' title='JSON documentation'>JSON documentation</a>)</p>
<p><strong>License:</strong><br />
Use it for whatever you want but be sure to leave the credits to the creator(s) within the code. If you don't change it you can get always the latest update here ;)</p>
<p><strong>Change Log:</strong><br />
<a href="http://www.webdevbros.net/wp-content/uploads/2008/07/json151.zip">v1.5.1</a> (15.07.2008)</p>
<ul>
<li>bugfix: didnt work properly with empty dictionaries. fixed!</li>
</ul>
<p><a href="http://www.webdevbros.net/wp-content/uploads/2008/07/json15.zip">v1.5</a> (10.07.2008)</p>
<ul>
<li>bugfix: utf-8 fully supported now (e.g. chinese didnt work)</li>
<li>bugfix: empty dictionaries werent represented. now represented as 'null'</li>
<li>toJSON() is defined as default method</li>
<li>paged recordsets supported</li>
<li>asp request object, IStringList and IRequestDictionary supported</li>
<li>updated documentation</li>
<li><a href="http://www.webdevbros.net/2008/07/10/asp-json-utility-version-15-released/">detailed information (examples, ...) about the changes</a></li>
</ul>
<p><a href='http://www.webdevbros.net/wp-content/uploads/2007/12/json141.zip' title='JSON 1.4.1'>v1.4.1</a> (19.12.2007)</p>
<ul>
<li>minor bugfix immediately after the 1.4 release</li>
</ul>
<p>v1.4 (18.12.2007)</p>
<ul>
<li>there used to be an error when returning custom objects which were processed recursively. it resulted in outputing only '}'. this has been fixed.</li>
<li>vartype 19 was not recognized as integer, but is now (comes from mysql)</li>
<li>vartype 7 was not recognized as float, but is now</li>
</ul>
<p>v1.3 (21.08.2007)</p>
<ul>
<li>Option Explicit can be used now</li>
<li>Multidimensional arrays are supported (unlimited dimensions)</li>
</ul>
<p>v1.2 (19.07.2007)</p>
<ul>
<li>Nested dictionaries were are not generated with toResponse = false. Fixed</li>
<li>Currency and Byte datatype were not generated correctly. Fixed</li>
</ul>
<p>v1.1 (17.05.2007)</p>
<ul>
<li>Bug with Floats has been fixed</li>
</ul>
<table style="background-color: #fff; padding: 5px;" cellspacing=0>
<tr>
<td>
  <img src="http://groups.google.com/groups/img/3nb/groups_bar_de.gif" height=26 width=132 alt="Google Groups">
  </td>
</tr>
<tr>
<td style="padding-left: 5px;font-size: 125%">
  <b>asp-ajaxed</b>
  </td>
</tr>
<tr>
<td style="padding-left: 5px"> <a href="http://groups.google.com/group/asp-ajaxed">JSON is part of ajaxed. So you can check the ajaxed discussion group for more discussion about it.</a> </td>
</tr>
</table>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/&amp;t=Generate+JSON+from+VBScript+%28ASP%29+datatypes+&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/&amp;title=Generate+JSON+from+VBScript+%28ASP%29+datatypes+&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/&amp;title=Generate+JSON+from+VBScript+%28ASP%29+datatypes+&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Generate+JSON+from+VBScript+%28ASP%29+datatypes+;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/feed/</wfw:commentRss>
		<slash:comments>181</slash:comments>
		</item>
		<item>
		<title>JSON character escaping function in classic ASP</title>
		<link>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/</link>
		<comments>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 10:14:51 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>

		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=32</guid>
		<description><![CDATA[If you are into advanced AJAX techniques you probably will stumble across JSON (www.json.org) which makes developing (and therefore the life) a lot easier when working with AJAX. If you already stumbled across and you use JSON within classic ASP you might find this article useful. It deals with escaping characters for JSON acording to the RFC4627#2.5 I haven't found any snippet out there [...]]]></description>
			<content:encoded><![CDATA[<p>If you are into advanced AJAX techniques you probably will stumble across JSON (<a href="http://www.json.org/">www.json.org</a>) which makes developing (and therefore the life) a lot easier when working with AJAX. If you already stumbled across and you use JSON within classic ASP you might find this article useful. It deals with escaping characters for JSON acording to the <a target="_blank" href="http://www.ietf.org/rfc/rfc4627.txt?number=4627">RFC4627#2.5</a><span id="more-32"></span></p>
<p>I haven't found any snippet out there for classic ASP so we had to write our own. And so my work colleague - an old algorithm guru - just came up with this function which covers all the requirements specified in the JSON RFC.</p>
<p>What we want to achieve...</p>
<div class="igBar"><span id="lasp-36"><a href="#" onclick="javascript:showCodeTxt('asp-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-36">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>foo:<span style="color:#CC0000;">"&lt;%= "</span>some va<span style="color:#CC0000;">""</span>lue<span style="color:#CC0000;">" %&gt;"</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">foo</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The code snippet above will result in a javascript error because we are passing an apostrophe from ASP to Javascript which leads to an early closing of the string: foo:"some va"lue" (there is one apostrophe too much). The same thing happens for other characters as well. If you have line breaks, german umlaute, hidden special characters, etc. All those need to be escaped now in order that the javascript simple object notation (JSON) can interpret it. Thats the function which does the escaping (there are 3 more functions cause they're used within the escapeJSON()):</p>
<div class="igBar"><span id="lasp-37"><a href="#" onclick="javascript:showCodeTxt('asp-37'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-37">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'******************************************************************************************</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'' @SDESCRIPTION:&nbsp; &nbsp;takes a given string and makes it JSON valid (http://json.org/)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'' @AUTHOR:&nbsp;Michael Rebec</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'' @DESCRIPTION:&nbsp; &nbsp; all characters which needs to be escaped are beeing replaced by their</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">''&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unicode representation according to the </span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">''&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RFC4627#2.5 - http://www.ietf.org/rfc/rfc4627.txt?number=4627</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'' @PARAM:&nbsp; &nbsp; &nbsp; val [string]: value which should be escaped</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'' @RETURN:&nbsp;&nbsp;&nbsp;[string] JSON valid string</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">'******************************************************************************************</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">public</span> <span style="color:#0000FF; font-weight:bold;">function</span> escapeJSON<span style="color:#006600; font-weight:bold;">&#40;</span>val<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cDoubleQuote = &amp;h22</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cRevSolidus = &amp;h5C</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cSolidus = &amp;h2F</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> i = <span style="color:#800000;color:#800000;">1</span> <span style="color:#990099; font-weight:bold;">to</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">len</span><span style="color:#006600; font-weight:bold;">&#40;</span>val<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; currentDigit = <span style="color:#990099; font-weight:bold;">mid</span><span style="color:#006600; font-weight:bold;">&#40;</span>val, i, <span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; &amp;h00 <span style="color:#0000FF; font-weight:bold;">and</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span> &lt;&amp;h1F <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentDigit = escapeJSONSquence<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">elseif</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span>&gt;= &amp;hC280 <span style="color:#0000FF; font-weight:bold;">and</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span> &lt;= &amp;hC2BF <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentDigit = <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\u</span>00"</span> + <span style="color:#990099; font-weight:bold;">right</span><span style="color:#006600; font-weight:bold;">&#40;</span>padLeft<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">hex</span><span style="color:#006600; font-weight:bold;">&#40;</span>asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span> - &amp;hC200<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">elseif</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span>&gt;= &amp;hC380 <span style="color:#0000FF; font-weight:bold;">and</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span> &lt;= &amp;hC3BF <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentDigit = <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\u</span>00"</span> + <span style="color:#990099; font-weight:bold;">right</span><span style="color:#006600; font-weight:bold;">&#40;</span>padLeft<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">hex</span><span style="color:#006600; font-weight:bold;">&#40;</span>asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span> - &amp;hC2C0<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">else</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">select</span> <span style="color:#990099; font-weight:bold;">case</span> asc<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">case</span> cDoubleQuote: currentDigit = escapeJSONSquence<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">case</span> cRevSolidus: currentDigit = escapeJSONSquence<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">case</span> cSolidus: currentDigit = escapeJSONSquence<span style="color:#006600; font-weight:bold;">&#40;</span>currentDigit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">select</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; escapeJSON = escapeJSON &amp; currentDigit</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">function</span> escapeJSONSquence<span style="color:#006600; font-weight:bold;">&#40;</span>digit<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; escapeJSONSquence = <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\u</span>00"</span> + <span style="color:#990099; font-weight:bold;">right</span><span style="color:#006600; font-weight:bold;">&#40;</span>padLeft<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">hex</span><span style="color:#006600; font-weight:bold;">&#40;</span>asc<span style="color:#006600; font-weight:bold;">&#40;</span>digit<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">function</span> padLeft<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#330066;">value</span>, totalLength, paddingChar<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; padLeft = <span style="color:#990099; font-weight:bold;">right</span><span style="color:#006600; font-weight:bold;">&#40;</span>clone<span style="color:#006600; font-weight:bold;">&#40;</span>paddingChar, totalLength<span style="color:#006600; font-weight:bold;">&#41;</span> &amp; <span style="color:#330066;">value</span>, totalLength<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">public</span> <span style="color:#0000FF; font-weight:bold;">function</span> clone<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">byVal</span> str, n<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> i = <span style="color:#800000;color:#800000;">1</span> <span style="color:#990099; font-weight:bold;">to</span> n : clone = clone &amp; str : <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So now we should be able to escape the strings for JSON like this and no error should occur...</p>
<div class="igBar"><span id="lasp-38"><a href="#" onclick="javascript:showCodeTxt('asp-38'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-38">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>foo:<span style="color:#CC0000;">"&lt;%= escapeJSON("</span>some va<span style="color:#CC0000;">""</span>lue<span style="color:#CC0000;">") %&gt;"</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">foo</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">&lt;/script&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This stuff has been tested and works for all characters so everything can be transfered with JSON now ;) I would suggest to group the whole functions into a class called JSON with a method escape() just for a nicer use. In my case its in a utility class StringOperations where I have several string manipulation methods. If you are interested you can download the full String class also which include the JSON escaping method:</p>
<p><a href="/wp-content/uploads/2007/04/string.zip" title="StringOperations 0.9">StringOperations 0.9</a> (<a target="_blank" href="/wp-content/uploads/2007/04/stringoperations.html" title="StringOperations Documentation">StringOperations Documentation</a>)</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/&amp;t=JSON+character+escaping+function+in+classic+ASP&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/&amp;title=JSON+character+escaping+function+in+classic+ASP&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/&amp;title=JSON+character+escaping+function+in+classic+ASP&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=JSON+character+escaping+function+in+classic+ASP;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

