<?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>Shawn McCool &#187; JavaScript</title>
	<atom:link href="http://shawnmccool.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://shawnmccool.com</link>
	<description>a blog about web and game development</description>
	<lastBuildDate>Mon, 15 Feb 2010 14:23:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AJAX with jQuery: A Simple Login Example</title>
		<link>http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/</link>
		<comments>http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 23:04:23 +0000</pubDate>
		<dc:creator>Shawn McCool</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[screencast]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://shawnmccool.com/?p=259</guid>
		<description><![CDATA[In this screencast we explore the jQuery $.post() command in order to create a simple ajax login script that also gracefully degrades and works for users who do not have JavaScript enabled.



Related posts:<ol><li><a href='http://shawnmccool.com/2009/03/26/ajax-with-jquery-the-beginning/' rel='bookmark' title='Permanent Link: AJAX with jQuery: The Beginning'>AJAX with jQuery: The Beginning</a></li>
<li><a href='http://shawnmccool.com/2009/04/15/what-exactly-is-json/' rel='bookmark' title='Permanent Link: What exactly is JSON?'>What exactly is JSON?</a></li>
<li><a href='http://shawnmccool.com/2009/09/04/developing-a-website-with-code-igniter-part-1-configuration/' rel='bookmark' title='Permanent Link: Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration'>Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this screencast we explore the jQuery $.post() command in order to create a simple ajax login script that also gracefully degrades and works for users who do not have JavaScript enabled.</p>
<p>You may want to check out my post <a title="What Exactly is JSON?" href="http://shawnmccool.com/2009/04/15/what-exactly-is-json/">&#8216;What Exactly is JSON?&#8217;</a> if you&#8217;re not familiar with the JavaScript Object Notation before watching.</p>


<p>Related posts:<ol><li><a href='http://shawnmccool.com/2009/03/26/ajax-with-jquery-the-beginning/' rel='bookmark' title='Permanent Link: AJAX with jQuery: The Beginning'>AJAX with jQuery: The Beginning</a></li>
<li><a href='http://shawnmccool.com/2009/04/15/what-exactly-is-json/' rel='bookmark' title='Permanent Link: What exactly is JSON?'>What exactly is JSON?</a></li>
<li><a href='http://shawnmccool.com/2009/09/04/developing-a-website-with-code-igniter-part-1-configuration/' rel='bookmark' title='Permanent Link: Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration'>Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>What exactly is JSON?</title>
		<link>http://shawnmccool.com/2009/04/15/what-exactly-is-json/</link>
		<comments>http://shawnmccool.com/2009/04/15/what-exactly-is-json/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 22:04:19 +0000</pubDate>
		<dc:creator>Shawn McCool</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://shawnmccool.com/?p=254</guid>
		<description><![CDATA[JSON is short for JavaScript Object Notation.  It's a notation used to create JavaScript objects...


Related posts:<ol><li><a href='http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/' rel='bookmark' title='Permanent Link: AJAX with jQuery: A Simple Login Example'>AJAX with jQuery: A Simple Login Example</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>JSON is short for JavaScript Object Notation.  It&#8217;s a notation used to create JavaScript objects.</p>
<p>JSON looks like this:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br />
<br />
<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Shawn McCool&quot;</span><span style="color: #339933;">,</span><br />
<br />
language<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;English&quot;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>When evaluated by JavaScript or <a title="JSON decode documentation from PHP.net" href="http://www.php.net/json_decode">decoded with another language</a> you&#8217;d end up with an object like the one below.</p>
<blockquote><p>person.name is equal to &#8220;Shawn McCool&#8221;</p>
<p>person.language is equal to &#8220;English&#8221;.</p></blockquote>
<p>Since using JSON allows you to easily <a title="Wiki article on serialization" href="http://en.wikipedia.org/wiki/Serialization">serialize</a> arrays and objects, it&#8217;s often used during AJAX calls and web services. Below are some examples of the JavaScript Object Notation.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> myArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'cat'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'dog'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> myObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>animal<span style="color: #339933;">:</span> <span style="color: #3366CC;">'cow'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// outputs 'cat'</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myObject.<span style="color: #660066;">animal</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 'cow';</span></div></div>
<h3>A standard set of interactions for an AJAX login script might be:</h3>
<p>1: JavaScript client (browser) posts username and password to PHP.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/ajax.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><br />
username<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=username]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <br />
password<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=password]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>2: PHP authenticates the information against the database then generates a response which is json_encoded and sent to the browser.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$user <span style="color: #339933;">=</span> $this<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>auth_model<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Login<span style="color: #009900;">&#40;</span>$_POST<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> $_POST<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$user<span style="color: #009900;">&#41;</span><br />
<br />
<span style="color: #009900;">&#123;</span><br />
$data<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">else</span><br />
<br />
<span style="color: #009900;">&#123;</span><br />
$data<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><br />
<br />
echo json_encode<span style="color: #009900;">&#40;</span>$data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>3: JavaScript client ‘eval’uates the JSON which creates an object. JavaScript client then determines behavior based on the data in the object.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/ajax.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>username<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=username]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> password<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=password]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">success</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// login succeeded</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// login failed</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>


<p>Related posts:<ol><li><a href='http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/' rel='bookmark' title='Permanent Link: AJAX with jQuery: A Simple Login Example'>AJAX with jQuery: A Simple Login Example</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shawnmccool.com/2009/04/15/what-exactly-is-json/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AJAX with jQuery: The Beginning</title>
		<link>http://shawnmccool.com/2009/03/26/ajax-with-jquery-the-beginning/</link>
		<comments>http://shawnmccool.com/2009/03/26/ajax-with-jquery-the-beginning/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 01:40:53 +0000</pubDate>
		<dc:creator>Shawn McCool</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://shawnblog.info/?p=178</guid>
		<description><![CDATA[This is the first in a series of screencasts that I'm creating to highlight the AJAX functionality present in the open source Javascript framework jQuery. In this screencast I give a brief overview of AJAX as well as delve into our first jQuery command.


Related posts:<ol><li><a href='http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/' rel='bookmark' title='Permanent Link: AJAX with jQuery: A Simple Login Example'>AJAX with jQuery: A Simple Login Example</a></li>
<li><a href='http://shawnmccool.com/2009/09/04/developing-a-website-with-code-igniter-part-1-configuration/' rel='bookmark' title='Permanent Link: Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration'>Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration</a></li>
<li><a href='http://shawnmccool.com/2009/08/29/understand-the-structure-of-code-igniter/' rel='bookmark' title='Permanent Link: Understand the Structure of CodeIgniter'>Understand the Structure of CodeIgniter</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is the first in a series of screencasts that I&#8217;m creating to highlight the AJAX functionality present in the open source Javascript framework jQuery. In this screencast I give a brief overview of AJAX as well as delve into our first jQuery command.</p>
<p>* SCRIPT *</p>
<p>AJAX stands for Asynchronous JavaScript and XHTML (or XML, depending on who you ask).</p>
<p>Since you&#8217;re watching this you probably already know that it&#8217;s a technology that allows us to send and receive data to and from a web server without having to reload our web page.</p>
<p>I&#8217;ve already created a project for us and have included the most recent copy of jQuery. So, let&#8217;s go ahead and create an index.html file.</p>
<p>Now, I&#8217;m going to go ahead and include the jQuery script file and add script tags and a container to work with.</p>
<p>It&#8217;s probably important to add that we should never actually mix JavaScript and HTML in the same file.  But, we&#8217;re going to go ahead and do it here for demonstration purposes.</p>
<p>jQuery comes stock with a handful of powerful AJAX commands.  For now, we&#8217;re going to focus on the load command.  The load command allows us to replace the HTML in a wrapped set with HTML that we&#8217;re pulling from another file on our website.</p>
<p>What we&#8217;re going to do is we&#8217;re going to want to wait until the DOM has loaded by using the ready command and then once the DOM has loaded let&#8217;s go ahead and select the console and pull in some HTML from a file called listitems.html. We haven&#8217;t actually created this file yet so let&#8217;s go ahead and do that.</p>
<p>Let&#8217;s go ahead and create an unordered list with the firstList class and we&#8217;ll go ahead and copy and paste that and create a second list.</p>
<p>Alright, so we can imagine this as a side navigation or something along those lines. Let&#8217;s go back to our index.html file and we&#8217;re ready to run.</p>
<p>So, let&#8217;s load the page and as you can see it loads in the contents of the listitems.html file.</p>
<p>Let&#8217;s go ahead and add a button for more interactivity.  We&#8217;ll go ahead and name it actionButton.  Next, we&#8217;ll want to bind the click event of the action button and execute our AJAX load.</p>
<p>Let&#8217;s go ahead and reload the page.  We have our click me button. We click it and it loads the content.</p>
<p>One of the reasons the load command is so powerful is that it allows us to define a selector.  We can actually use a selector to select a subset of content from the listitems.html file. An example would be if we wanted to just select the content from the second list.  We could tell it that we want to select anything with the class secondList.</p>
<p>So, we&#8217;ll save it and load. Click, and we only pull back the second list. We can drill down even deeper by only selecting the even list items.</p>
<p>As you can see we were able to accomplished a lot with very little code.  But, we&#8217;re just beginning to scratch the surface of the functionality that jQuery provides for AJAX interactions.</p>
<p>And with that we conclude the first screencast on AJAX with jQuery.  My name is Shawn McCool. Thanks for watching.</p>


<p>Related posts:<ol><li><a href='http://shawnmccool.com/2009/04/15/ajax-with-jquery-a-simple-login-example/' rel='bookmark' title='Permanent Link: AJAX with jQuery: A Simple Login Example'>AJAX with jQuery: A Simple Login Example</a></li>
<li><a href='http://shawnmccool.com/2009/09/04/developing-a-website-with-code-igniter-part-1-configuration/' rel='bookmark' title='Permanent Link: Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration'>Developing a Website with CodeIgniter Part 1: Development Environment and Framework Configuration</a></li>
<li><a href='http://shawnmccool.com/2009/08/29/understand-the-structure-of-code-igniter/' rel='bookmark' title='Permanent Link: Understand the Structure of CodeIgniter'>Understand the Structure of CodeIgniter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shawnmccool.com/2009/03/26/ajax-with-jquery-the-beginning/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
