<?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>thecrumb.com &#187; ajax</title>
	<atom:link href="http://thecrumb.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecrumb.com</link>
	<description>developer &#124; thinker &#124; tinkerer</description>
	<lastBuildDate>Sat, 04 Feb 2012 01:28:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>John Resig on Accessibility, ARIA and Fire Vox</title>
		<link>http://thecrumb.com/2008/04/30/john-resig-on-accessibility-aria-and-fire-vox/</link>
		<comments>http://thecrumb.com/2008/04/30/john-resig-on-accessibility-aria-and-fire-vox/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 13:00:49 +0000</pubDate>
		<dc:creator>Jim Priest</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.thecrumb.com/?p=438</guid>
		<description><![CDATA[I&#8217;ve been using jQuery more and more at work but have been having to hold off some of the more advanced uses because of accessibility concerns. Working with the Government we are looking more and more at 508 and accessibility &#8230; <a href="http://thecrumb.com/2008/04/30/john-resig-on-accessibility-aria-and-fire-vox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using jQuery more and more at work but have been having to hold off some of the more advanced uses because of accessibility concerns. Working with the Government we are looking more and more at 508 and accessibility and right now AJAX is a bit of a gray area.</p>
<p>Today John Resig (author of jQuery) has a great blog post about <a href="http://ejohn.org/blog/ajax-accessibility/">Ajax Accessibility</a> in which he discusses Google&#8217;s use of <a href="http://www.w3.org/TR/wai-aria/">ARIA</a> in Google Reader and also mentions  <a href="http://firevox.clcworld.net/">Fire Vox:</a></p>
<blockquote><p>Fire Vox is an open source, freely available talking browser extension for the Firefox web browser. Think of it as a screen reader that is designed especially for Firefox.</p>
<p>In addition to the basic features that are expected of screen readers, such as being able to identify headings, links, images, etc. and providing navigational assistance, Fire Vox provides support for MathML and CSS speech module properties. It also works on Windows, Macintosh, and Linux.</p></blockquote>
<p>I&#8217;ll certainly be setting this up today to give it a whirl! If you are interesting in accessibility, 508, and AJAX I&#8217;d check out John&#8217;s post!</p>
]]></content:encoded>
			<wfw:commentRss>http://thecrumb.com/2008/04/30/john-resig-on-accessibility-aria-and-fire-vox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fetching Data With jQuery</title>
		<link>http://thecrumb.com/2007/11/30/fetching-data-with-jquery/</link>
		<comments>http://thecrumb.com/2007/11/30/fetching-data-with-jquery/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 17:53:32 +0000</pubDate>
		<dc:creator>Jim Priest</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.thecrumb.com/2007/11/30/fetching-data-with-jquery/</guid>
		<description><![CDATA[I&#8217;ve been doing more and more with jQuery and thought I&#8217;d post a few examples. In my current project I&#8217;m building a really huge form for people to fill out if they want to work from home. The form needs &#8230; <a href="http://thecrumb.com/2007/11/30/fetching-data-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing more and more with jQuery and thought I&#8217;d post a few examples.  In my current project I&#8217;m building a really huge form for people to fill out if they want to work from home.  The form needs to be approved by different people depending on your division.  So on my form I have a series of radio buttons and based on the users selection the form will submit the request to the appropriate manager.  I wanted to provide some form of visual feedback and came up with this:</p>
<p><img src='http://thecrumb.com/wp-content/uploads/2007/11/jquery-fetch.gif' alt='Fetching Data with jQuery' /></p>
<p>Now lets take a look at the code to see how I did it&#8230; <span id="more-249"></span></p>
<p>First my form is generated dynamically so I&#8217;ve simplified it quite a bit for this example:</p>
<p><strong>My form:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;editfield&quot;&gt;
	 OD
	 OM
	 DERT
	 DIR
	 NTP
	 ORAR
&lt;/div&gt;

&lt;div&gt;Loading... &lt;/div&gt;

&lt;label for=&quot;approval&quot;&gt;Approving Official Signature&lt;/label&gt;
</pre>
<p>This gives me my series of radio buttons, a div to contain my &#8220;Loading&#8221; animation, and finally the text field which will receive my approvers name.</p>
<p>For the dynamic loading graphic &#8211; there are a <a href="http://del.icio.us/thecrumb/ajax">few sites </a>out there with graphics you can grab or create.  Then it&#8217;s a simple matter of creating a div container to display it and some simple CSS:</p>
<p><strong>Loading CSS:</strong></p>
<pre class="brush: css; title: ; notranslate">

#loading {
	background: #fff url('../img/ajax-loading.gif') left no-repeat;
	color: #369;
	display: none;
	font-weight: bold;
	margin: 1em 0;
	padding-left: 20px;
	}
</pre>
<p>This initially hides the loading graphic (display: none) and we&#8217;ll later use jQuery to flip that on when we need it.</p>
<p>Next &#8211; the <a href="http://jquery.com/">jQuery</a> magic!  For help installing and getting jQuery setup &#8211; check out the &#8220;<a href="http://docs.jquery.com/How_jQuery_Works">How jQuery Works</a>&#8221; tutorial on the jQuery wiki.</p>
<p>For this example &#8211; I&#8217;m also using the <a href="http://www.malsup.com/jquery/form/">jQuery Form plugin</a>. This provides the <em>fieldValue</em> method which allows me to grab the value of the selected radio button.</p>
<p>We&#8217;re going to assume you have the jQuery library and form plugin loaded&#8230; here is the jQuery code:</p>
<pre class="brush: jscript; title: ; notranslate">

	$(document).ready(function(){
		$(&quot;input:radio[@name='divisionid']&quot;).click(function() {
			var foo = $(this).fieldValue();
			$.ajax({
	  			type: &quot;POST&quot;,
	  			url: &quot;index.cfm?action=telework.getchief&quot;,
	  			dataType: &quot;html&quot;,
	  			cache: false,
	  			data: &quot;divisionid=&quot; + foo,
	  			success: function(msg) {
	  				$('#approval_2_Yes_2').val(foo);
	  				$('#approval_2_Yes_2_dsp').val(msg);
	  				// alert('Division ID = ' + foo);
					}
			});
		});
	});
</pre>
<p>So let&#8217;s step through this&#8230;</p>
<p>First we grab the radio button value (divisionid) when a user clicks on one of the radio buttons. We then assign the value of that radio button (this) to a variable (foo).</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;input:radio[@name='divisionid']&quot;).click(function() {
var foo = $(this).fieldValue();
});
</pre>
<p>One thing to remember when working with CSS and jQuery &#8211; some things are case sensitive &#8211; so &#8216;divisionid&#8217; != &#8216;divisionID&#8217;.</p>
<p>Next we setup our Ajax call &#8211; this is all you need in jQuery to make an Ajax request.  I&#8217;d suggest checking out the <a href="http://docs.jquery.com/Ajax">jQuery docs on Ajax</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
$.ajax({
	type: &quot;POST&quot;,
	url: &quot;index.cfm?action=telework.getchief&quot;,
	dataType: &quot;html&quot;,
	cache: false,
	data: &quot;divisionid=&quot; + foo,
	success: function(msg) {
	}
});
</pre>
<p>Here we are setting up our Ajax request parameters:</p>
<ul>
<li><strong>Type</strong>: we are going to make a POST request</li>
<li><strong>URL</strong>: the URL where we are going to fetch our data from</li>
<li><strong>DataType</strong>:  What we are going to return &#8211; in our example we&#8217;ll just fetch a simple HTML string</li>
<li><strong>Cache</strong>:  Whether or not to cache the results</li>
<li><strong>Success</strong>: What to do on a successful request</li>
</ul>
<p>Behind the scenes this is a Fusebox application &#8211; so when the user clicks a radio button &#8211; jQuery makes a request to <em>index.cfm?action=telework.getchief</em>.  This does all kinds of Fusebox stuff but eventually runs a query using the data we passed in (data: &#8220;divisionid=&#8221; + foo &#8211; ie:  divisionid=4).</p>
<p><strong>Query using divisionID as argument:</strong></p>
<pre class="brush: plain; title: ; notranslate">

		select
			signature_name
                        , org
		from
			tbldivision
		where
			divisionid = #arguments.divisionid#
</pre>
<p>This is returned to a very simply layout with no HTML:</p>
<pre class="brush: plain; title: ; notranslate">
#qryApprovers.signature_name &amp;amp; &quot; (&quot; &amp;amp; (qryApprovers.org) &amp;amp; &quot;)&quot;#
</pre>
<p>And if the request is successful &#8211; we write our string back to our form field (the alert is handy for testing):</p>
<pre class="brush: jscript; title: ; notranslate">
success: function(msg) {
  $('#approval').val(foo);
  $('#approval_dsp').val(msg);
  // alert('Division ID = ' + foo);
}
</pre>
<p>Here I&#8217;m writing our original radio button value (foo) to a hidden field (approval).  I&#8217;m also writing the results of our Ajax request (msg) to my display field (approval_dsp) which overwrites the existing value &#8216;(select division above)&#8217;.</p>
<p>So this should work &#8211; (unless I&#8217;ve bungled something up) &#8211; but there is no indication to the user anything is happening.  We want Web 2.0 and need a spinning &#8216;loading&#8217; graphic!</p>
<p>jQuery makes this super easy by providing the ajaxStart and ajaxStop methods:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#loading').ajaxStart(function() {
  $(this).show();
}).ajaxStop(function() {
  $(this).hide();
});
</pre>
<p>So now we&#8217;re simply saying &#8211; when an Ajax request starts &#8211; show $(this) which is our <em>#loading</em> div which we had originally set to display: none in our CSS. When the Ajax request finishes we hide it again.  Simple!</p>
<p>Hopefully this example has piqued your interest in jQuery and demonstrated how easy it is to use.  If you have questions, comments or suggestions on how to improve the jQuery above &#8211; please leave me a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://thecrumb.com/2007/11/30/fetching-data-with-jquery/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

