<?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>SwellJS - another big fish in the sea &#187; JSON</title>
	<atom:link href="http://blog.justswell.org/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.justswell.org</link>
	<description>well-minded javascript library</description>
	<lastBuildDate>Fri, 20 Aug 2010 20:48:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Ajax: Form Serialization</title>
		<link>http://blog.justswell.org/ajax-form-serialization/</link>
		<comments>http://blog.justswell.org/ajax-form-serialization/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 11:26:29 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Swell]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://blog.justswell.org/?p=121</guid>
		<description><![CDATA[When using Ajax to submit a form, you&#8217;ll have to attach as args the input fields name/value combination; this task can be very boring, especially if your form takes three pages&#8230; This is where the form serialization feature strikes, by simply specifying the form(s) name to your XHR handle, the serializer will parse through your [...]]]></description>
			<content:encoded><![CDATA[<p>When using Ajax to submit a form, you&#8217;ll have to attach as args the input fields name/value combination; this task can be very boring, especially if your form takes three pages&#8230;<br />
This is where the form serialization feature strikes, by simply specifying the form(s) name to your XHR handle, the serializer will parse through your form and assemble each content input field into an object that&#8217;ll be passed automatically to your request.</p>
<p>We made a choice that come very handy in our case, every serialized form is returned in a global object and once requested, &#8220;stringified&#8221;.<br />
Why using JSON?<br />
In some case, let&#8217;s say&#8230; in &#8220;multiples select&#8221;, we can come up with multiple values, and when using GET you&#8217;ll definitely do something like <em>key=val</em>, with multiple values, <em>key[]=val</em>, but how much server-side languages can handle this kind of GET property? not much&#8230; whereas much languages are now able to unserialize JSON.</p>
<p>PHP is able to &#8220;decipher&#8221; passed arrays in GET, but what about the others languages? If there&#8217;s Java/Ruby/ASP.NET folks out there, we would like to hear from you!</p>
<h2 style="padding-top:10px;">XHR in Element</h2>
<p>In order to save both time and lines, it was quite interesting to think of a way to implement XHR in our Element class, take a look at these working drafts:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// well, let's say we have two forms</span>
<span style="color: #003366; font-weight: bold;">var</span> forms <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'foo'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// will send them separately asychronously</span>
forms.<span style="color: #660066;">xhr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// this time we want to harmonize their form[method] value</span>
forms.<span style="color: #660066;">xhr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// or their form[action] value</span>
forms.<span style="color: #660066;">xhr</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'foo.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// two concurrent ajax request is somehow too much, we'd better merge them!</span>
forms.<span style="color: #660066;">xhr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'foo.php'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.justswell.org/ajax-form-serialization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

