<?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>Joe Junkin &#187; post</title>
	<atom:link href="http://joe.junkin.com/tag/post/feed/" rel="self" type="application/rss+xml" />
	<link>http://joe.junkin.com</link>
	<description>Life as it happens</description>
	<lastBuildDate>Thu, 14 Jan 2010 23:34:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Strange server errors posting an Ajax form</title>
		<link>http://joe.junkin.com/2008/03/26/issues-posting-a-form-using-ajax/</link>
		<comments>http://joe.junkin.com/2008/03/26/issues-posting-a-form-using-ajax/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 21:50:25 +0000</pubDate>
		<dc:creator>jjunkin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[server error]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://joe.junkin.com/2008/03/26/issues-posting-a-form-using-ajax/</guid>
		<description><![CDATA[I just wrestled with getting a form to post via ajax. I have done this before but had a bunch of issues crop up this time including strange intermitten server errors that only seemed to occur on Firefox. I resolved it by using the extremely handy YUI connection manager &#8217;setForm&#8217; function to process the data for me. [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrestled with getting a form to post via ajax. I have done this before but had a bunch of issues crop up this time including strange intermitten server errors that only seemed to occur on Firefox. I resolved it by using the extremely handy YUI connection manager &#8217;setForm&#8217; function to process the data for me. I also found a problem when submitting a non-rails created form that caused an ctionController::InvalidAuthenticityToken error.</p>
<p><span id="more-35"></span></p>
<p>I was sending the form by using a javascript function to get each field, concatonate a url (using escape) and use the YUI connection manager with a GET method. This caused intermitten errors on firefox including one like &#8216;the server did not understand the request&#8217; (or something like that). What was happening was the escape was creating a series of chars that triggered a mod_security rule. The rule was blocking access to the rails server.</p>
<p><code>ModSecurity: Access denied with code 400 (phase 2). Pattern match "%0[ad]" at REQUEST_URI. [id "950910"] [msg "HTTP Response Splitting Attack. Matched signature &lt;%0a&gt;"] [severity "ALERT"] [hostname "dev.removed.com"] [uri "/aSubmitContact?name=john%20johnson&amp;email=john@removed.com&amp;phone=123455&amp;msg=this%20is%20a%20test%0Athsi%20is%20only%20a%20test&amp;subject=general"]<br />
</code></p>
<p>I did some digging and discovered that YUI has a sweet function to fetch, prepare and send the form fields for me:</p>
<p><code>Connection Manager can automatically harvest HTML form data and prepare it for either a GET or POST request via the setForm method. When you call this method before initiating the transaction, Connection Manager constructs a GET querystring or a POST message from the form and submits it to the specified URL.</code></p>
<p>You simply hand the element to <code>YAHOO.util.Connect.setForm(formObject, true); </code>and the connection manager takes care of the rest. SWEET!</p>
<p>After that, another issue came up with rails. It seems that rails expects you to utilize it&#8217;s built-in form generator. When I submitted the form I built with javascript using the DOM, I got the error:</p>
<p><code>ActionController::InvalidAuthenticityToken</code></p>
<p>This appears to be due to a new feature in rails that attempts to stop cross-site-scripting by attaching an hidden identifier value to the form. I had to disable the feature for my javascript created form. To disable it I used:<br />
<code>protect_from_forgery <img src='http://joe.junkin.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt; [:update, :delete, :create].</code><br />
I realize that it is a nice feature, but it would be nice to see it as optional instead of default.</p>
]]></content:encoded>
			<wfw:commentRss>http://joe.junkin.com/2008/03/26/issues-posting-a-form-using-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
