<?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>Ryan Coughlin &#124; Web and Graphic Designer &#187; serialize</title>
	<atom:link href="http://www.ryancoughlin.com/tag/serialize/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryancoughlin.com</link>
	<description></description>
	<lastBuildDate>Fri, 26 Mar 2010 00:07:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use jQuery to Serialize Ajax Forms</title>
		<link>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/</link>
		<comments>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:17:08 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=455</guid>
		<description><![CDATA[When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.
Instead of declaring all of your data to [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.</p>
<p>Instead of declaring all of your data to be sent using something like:</p>
<pre class="js" title="code">
var fname     = $('#fname').attr('value');
var lname     = $('#lname').attr('value');
$.ajax({
     data: “fname=”+ fname + “&amp; lname=” + lname,
});
</pre>
<p>For a couple of fields above, that is fine, but what if you were creating a form with a large amount of fields. The last thing you would want to do is want to copy/paste that line 20 times for your field. Instead of grabbing each value of each form field we can use jQuery&#8217;s .serialize() to do the dirty work for us, which is a huge time saver. We can use something like:</p>
<pre class="js" title="code">
$(function() {
     $('form').bind('submit',function() { showValues(); return false; });
});
function showValues() {
     var str = $("form").serialize();
     $(".results-box").fadeIn();
     $(".results").text(str);
}
</pre>
<p>The first section binds the submit to a function. When a user submits the form call the function showValues(), the next bit. We grab the form and attach .serialize() to it. We want to serialize all fields within this form and display what data is going to be sent to the sever. A <a href="http://www.ryancoughlin.com/demos/serialize/jquery.serialize.html" target="_blank">working demo</a> has been uploaded.</p>
<p>Now with our data serialized it is ready to be sent over to the server side. Using jQuery .serialize() is much more effiecient compared to retrieving the value using .val().</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
