<?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>Search-This &#187; Ajax</title>
	<atom:link href="http://www.search-this.com/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.search-this.com</link>
	<description>Internet Marketing, Website Promotion and Blogging Advice</description>
	<lastBuildDate>Fri, 30 Apr 2010 18:22:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ASP.NET, LINQ, jQuery, JSON, Ajax &#8211; Oh my!</title>
		<link>http://www.search-this.com/2010/04/26/asp-net-linq-jquery-json-ajax-oh-my/</link>
		<comments>http://www.search-this.com/2010/04/26/asp-net-linq-jquery-json-ajax-oh-my/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 13:41:51 +0000</pubDate>
		<dc:creator>Golgotha</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Website Design]]></category>

		<guid isPermaLink="false">http://www.search-this.com/?p=1009</guid>
		<description><![CDATA[In this article we will be looking at a different type of architecture. One in which we utilize jQuery's ability to easily transfer data (via Ajax and JSON) from the client to the server. We then use ASP.NET and LINQ to SQL to query the database and return a collection of data which gets (automatically) [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we will be looking at a different type of architecture. One in which we utilize jQuery's ability to <strong>easily </strong>transfer data (via Ajax and JSON) from the client to the server. We then use ASP.NET and LINQ to SQL to query the database and return a collection of data which gets (automatically) serialized to JSON and sent to the client. The benefits of combining these technologies include: more responsive applications, more processing on the client, less processing on the server and reduced network traffic. Everything runs faster and uses fewer resources. </p>
<p>Still not convinced? Here are some additional benefits of this architecture:</p>
<h2>Benefits of the Architecture</h2>
<ol>
<li>Unlike an ASP.NET UpdatePanel we only pass what we need; we only receive what we need. We don’t pass ViewStates, in fact we don’t even have a ViewState. We also don’t pass entire HTML chunks and receive HTML chunks we don’t use. For more on this; read: <a href="http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/" target="_blank"><strong>Why ASP.NET AJAX UpdatePanels are dangerous.</strong></a></li>
<li>By using jQuery to call the web service directly, we’ve eliminated over 100 KB of JavaScript and three extra HTTP requests that's included when you use ASP.NET Ajax.</li>
<li>Less dependencies – because all our code is simply xHTML we could switch to a PHP or a Java backend and none of our code for the UI would have to change. That's right, there are no server-controls; that means no GridViews, no Repeaters, no ListViews, nothing that uses runat server will be found on the page.  Not even a ScriptManager.</li>
<li>Usability – We can create RIA interfaces AND maintain usability, giving us the best of both worlds.</li>
<li>Cross-Browser friendly – We use nothing but xHTML code and jQuery which works across browsers.</li>
<li>The entire presentation for the UI is done via CSS. Change the CSS and the entire UI can look different.</li>
<li>We maintain a '<a href="http://articles.sitepoint.com/article/simply-javascript" target="_blank"><strong>Separation of Concerns</strong></a>' - this means we have 3 distinct and wholly separate code bases. A content or HTML level. A presentation or CSS level and a behavior or JavaScript level. We don't have code mixed together in a web-page jambalaya.</li>
<li>Switching architectures from Web Forms to MVC is a breeze.
</ol>
<p>Hopefully you are salivating at these benefits enough to decide to get your feet wet and follow along.</p>
<p>In this article will be leveraging these technologies to build a grid (or what looks like a table). Later on, in future articles, I will then show you how to implement <em>sorting</em>, <em>paging </em>and <em>filtering </em>on the grid. I have divided this article up into four sections: 1. Sever-side code (ASP.NET). 2. HTML 3. jQuery and lastly CSS.</p>
<h2>ASP.NET</h2>
<p>In this article I will be using LINQ to SQL to query the database and return a collection. LINQ to SQL allows you to model a relational database using .NET classes. You can then query the database using LINQ, as well as update, insert and delete data from it. LINQ to SQL fully supports transactions, views, and stored procedures. If you're not familiar with LINQ then I will refer you to these articles: <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" target="_blank"><strong>Using LINQ to SQL (Part 1)</strong></a> and <a href="http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx" target="_blank"><strong>LINQ to SQL - 5 Minute Overview</strong></a>.</p>
<p>The goal of this article is not to teach you LINQ. But I will say that if you are not using LINQ and you are still using a DataReader or DataSet to access your data then shame on you. Simply put, I believe LINQ is the coolest technology Microsoft has come out with in recent years.</p>
<p>And the best news is, it's <em>EASY </em>to use. Let's look at the code:</p>
<div class="igBar"><span id="lcsharp-8"><a href="#" onclick="javascript:showPlainTxt('csharp-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-8">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CourseReservations</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">long</span> CourseId <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Course <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Time <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Holes <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Golfers <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FirstName <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> LastName <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#91;</span>WebMethod<span style="color: #000000;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">public</span> List&lt;CourseReservations&gt; GetGolfCourseReservations<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>DataContext dc = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; var query = from res <span style="color: #0600FF;">in</span> dc.<span style="color: #0000FF;">GolfReservations</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where res.<span style="color: #0000FF;">CourseId</span> == <span style="color: #FF0000;color:#800000;">1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CourseReservations</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CourseId = res.<span style="color: #0000FF;">CourseId</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Course = res.<span style="color: #0000FF;">GolfCourse</span>.<span style="color: #0000FF;">CourseName</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Time = res.<span style="color: #0000FF;">DataAndTime</span>.<span style="color: #0000FF;">ToShortTimeString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Holes = res.<span style="color: #0000FF;">Holes</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Golfers = res.<span style="color: #0000FF;">Golfers</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FirstName = res.<span style="color: #0000FF;">Aspnet_User</span>.<span style="color: #0000FF;">GolfUser</span>.<span style="color: #0000FF;">FirstName</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LastName = res.<span style="color: #0000FF;">Aspnet_User</span>.<span style="color: #0000FF;">GolfUser</span>.<span style="color: #0000FF;">LastName</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">return</span> query.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The first thing we do is create a class called CourseReservations. This class contains all the properties we will need to create our grid on the client. In other words, these will become our columns. The next part is our LINQ statement. This code uses LINQ query syntax to retrieve a sequence of GolfReservations for a given course.  Note how the code is querying across the GolfReservations / GolfCourse / Aspnet_User / GolfUser relationships to retrieve all the data we need from our tables, and we didn't have to write any SQL filled with JOINS to do it.</p>
<p>We then return a list of CourseReservations. What's important to note is that our list will get <strong>automatically </strong>serialized to JSON. How fantastic is that? Before we move on, also note the name of our method: <strong>GetGolfCourseReservations()</strong>. This is what we will call via Ajax using jQuery.</p>
<h2>HTML</h2>
<div class="igBar"><span id="lhtml-9"><a href="#" onclick="javascript:showPlainTxt('html-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-9">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">&lt;ul</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"reservationsList"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"stripedList"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>That's right, just a simple unordered list with an id of "reservationsList" and class of "stripedList". We don't use any controls, nothing with runat="server" will be found on the page. This way we don't have any ViewState taking up load time, nor do we have Microsoft inserting JavaScript into our page without our consent. Our page, at least on the front-end, is devoid of ASP.NET or any other language. Nothing but pure HTML. If we ever have to port to PHP or JSP we wouldn't have to change a single thing on the UI side.</p>
<h2>jQuery</h2>
<p>Let's look at the jQuery code now. Bit by bit.</p>
<div class="igBar"><span id="ljavascript-10"><a href="#" onclick="javascript:showPlainTxt('javascript-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-10">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//Ajax</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> SendAjax<span style="color: #66cc66;">&#40;</span>urlMethod, jsonData, returnFunction<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $.<span style="color: #006600;">ajax</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; type: <span style="color: #3366CC;">"POST"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; contentType: <span style="color: #3366CC;">"application/json; charset=utf-8"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; url: urlMethod,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; data: jsonData,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; dataType: <span style="color: #3366CC;">"json"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; success: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Do something interesting here.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>msg != <span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnFunction<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; error: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>xhr, <span style="color: #000066;">status</span>, error<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Boil the ASP.NET AJAX error down to JSON.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> err = <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"("</span> + xhr.<span style="color: #006600;">responseText</span> + <span style="color: #3366CC;">")"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Display the specific error raised by the server</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>err.<span style="color: #006600;">Message</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Notice the <strong>SendAjax()</strong> method's signature. It takes three parameters, the first <strong>urlMethod </strong>is the path to the Web Service followed by the name of the Web Method. It should look something like "webservice.asmx/webmethod". The second parameter <strong>jsonData </strong>will be exactly that, your JSON data. More on this later. The final parameter <strong>returnFunction</strong> will be the function you wish to call <em>after </em>the return trip from the server.</p>
<p>The <a href="http://api.jquery.com/jQuery.ajax/"><strong>$.ajax()</strong></a> method performs an asynchronous HTTP (Ajax) request. You can read all about it <a href="http://api.jquery.com/jQuery.ajax/">here</a>, but for now, just know it's the liaison for the client / server relationship; or the Ajax call.</p>
<p>We will use this light, but powerful SendAjax() method over and over again each time we wish to go to the server.</p>
<div class="igBar"><span id="ljavascript-11"><a href="#" onclick="javascript:showPlainTxt('javascript-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-11">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//Stripe the rows</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> StripeRows<span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $<span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'evenRow'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $<span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li:even'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'evenRow'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This function is simply used to stripe the rows. Every other row will be colored differently in our grid. You pass it a list, it then finds all the list items in that list and removes a class. It then adds a class to all the even list items. The reason why I removeClass() from all list items first is so that if you ever add or remove list items (dynamically) to the grid you don't get them all messed up colorwise.</p>
<div class="igBar"><span id="ljavascript-12"><a href="#" onclick="javascript:showPlainTxt('javascript-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-12">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//This fires when the DOM is ready</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">//So this starts the ball rolling...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; GetGolfCourseReservations<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you are new to jQuery then you need to start by understanding <strong>$(document).ready()</strong>. You can read all about it <a href="http://www.learningjquery.com/2006/09/introducing-document-ready"><strong>here</strong></a>. But the bottom line is that everything inside this method will load as soon as the DOM is loaded and before the page contents are loaded. This is extremely efficient because we don't have to wait for images or content to load, just the DOM elements. Again, if you are new to jQuery start by understanding the <strong>$(document).ready()</strong> method. </p>
<p>We are telling it to call the method GetGolfCourseReservations() as soon as browserly possible.</p>
<div class="igBar"><span id="ljavascript-13"><a href="#" onclick="javascript:showPlainTxt('javascript-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-13">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> GetGolfCourseReservations<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//Ajax</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> urlMethod = <span style="color: #3366CC;">"ws_Reservations.asmx/GetGolfCourseReservations"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> jsonData = <span style="color: #3366CC;">'{}'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; SendAjax<span style="color: #66cc66;">&#40;</span>urlMethod, jsonData, ReturnGetGolfCourseReservations<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> ReturnGetGolfCourseReservations<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> listItems = <span style="color: #3366CC;">""</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span>msg.<span style="color: #006600;">d</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>key, val<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listItems += <span style="color: #3366CC;">"&lt;li&gt;"</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c1'&gt;"</span> + val.<span style="color: #006600;">Time</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c2'&gt;"</span> + val.<span style="color: #006600;">FirstName</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c2'&gt;"</span> + val.<span style="color: #006600;">LastName</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c3'&gt;"</span> + val.<span style="color: #006600;">Course</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c4'&gt;"</span> + val.<span style="color: #006600;">Holes</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;span class='c4 cLast'&gt;"</span> + val.<span style="color: #006600;">Golfers</span> + <span style="color: #3366CC;">"&lt;/span&gt;"</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">"&lt;/li&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"#reservationsList"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>listItems<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; StripeRows<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#reservationsList'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The three lines in the GetGolfCourseReservations() method will become very familiar to you in this methodology. Recall that <strong>urlMethod</strong> is the path to your web service and your web method. You do remember our .asmx file contains a web method called GetGolfCourseReservations? Good. The next line with jsonData is the JSON that we are passing in. Note that if you are not passing any data, as we are in this case, you must still have the empty curly brackets. Finally, the third line is our call to SendAjax() method. Notice the third parameter: ReturnGetGolfCourseReservations. This is the method to be called on the round trip from the server. Conveniently you will find this function one line down. I always keep to this standard.</p>
<p>In our <strong>ReturnGetGolfCourseReservations</strong> method we loop through the returned JSON and create our rows or list items. We then drop our list items into our unordered list and lastly call our method to strip the rows. </p>
<blockquote><p>TIP: Two tools that are indispensable for this methodology are <a href="http://getfirebug.com/" target="_blank"><strong>Firebug</strong></a> and this <a href="http://braincast.nl/samples/jsoneditor/" target="_blank"><strong>JSON checker</strong></a>. Without Firebug you will not get far. It allows you to see all your Ajax calls, the post, the request and the returned JSON. Get it and learn it.</p></blockquote>
<h2>CSS</h2>
<p>Lastly, let's look at the CSS involved to make our grid look pretty. Do note that we could have used a table instead of a list very easily. It's your choice.</p>
<div class="igBar"><span id="lcss-14"><a href="#" onclick="javascript:showPlainTxt('css-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CSS:</span>
<div id="css-14">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;style type=<span style="color: #ff0000;">"text/css"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc00cc;">#reservationsList <span style="color: #66cc66;">&#123;</span></span>width:500px; max-<span style="color: #000000; font-weight: bold;">height</span>:600px; <span style="color: #000000; font-weight: bold;">background</span>:#fff; <span style="color: #000000; font-weight: bold;">overflow</span>:<span style="color: #993333;">auto</span>;<span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/*STRIPE LIST*/</span>&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ul<span style="color: #6666ff;">.stripedList </span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span>:<span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>:<span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">list-style</span>:<span style="color: #993333;">none</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.stripedList </span>li <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span>:<span style="color: #993333;">block</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-decoration</span>:<span style="color: #993333;">none</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>:#333;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span>:Arial,Helvetica,<span style="color: #993333;">sans-serif</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span>:12px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; line-<span style="color: #000000; font-weight: bold;">height</span>:20px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span>:20px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.stripedList </span>li span <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span>:inline-<span style="color: #993333;">block</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; border-right<span style="color: #3333ff;">:1px </span>solid #ccc;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">overflow</span>:<span style="color: #993333;">hidden</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; text-<span style="color: #000000; font-weight: bold;">overflow</span>:ellipsis;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; padding<span style="color: #3333ff;">:<span style="color: #cc66cc;color:#800000;">0</span> </span>10px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span>:20px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.stripedList </span><span style="color: #6666ff;">.evenRow </span><span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span>:#f2f2f2;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.c1 </span><span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span>:55px;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.c2 </span><span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span>:70px;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.c3 </span><span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span>:130px;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.c4 </span><span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span>:15px;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.cLast </span><span style="color: #66cc66;">&#123;</span>border<span style="color: #3333ff;">:<span style="color: #cc66cc;color:#800000;">0</span> </span>!important;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/style&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Most of the CSS is pretty straight forward; we stylize our list-items and use spans as our cells. The classes .c1, .c2 ect. allow us to assign a width to each column.</p>
<h2>The Take Away</h2>
<p>What I really want you to take away from this article is all the benefits gathered from this methodology. When I build Web-based apps the thing at the front of my mind is speed. It's all about speed. Nobody likes to wait for anything these days, on the web or off. This is about as fast as you can do things. In addition, we have nice clean code that adheres to the separation-of-concerns. On the front is just good old HTML, probably the first thing you learned when creating websites. On the back-end is our Web Service that does our actionable request: get, save, update and delete. That's all it does, it knows nothing about the UI, unlike a typical ASP.NET page with its CodeBehind page that is all aware of the UI and talks to it. If we ever had to change over to an Apache server and use PHP we wouldn't have to change a thing on the front-end, simply our methods on the back-end would change. </p>
<p>We allow our CSS file to control the way the entire application looks. Once again, compare this to many typical ASP.NET apps that use Web Controls and want you to set presentation properties either in the .aspx page or the CodeBehind page. Yuck. Never do that.</p>
<p>Lastly, not only is our code fast and clean, but it's also lean. When you get good at this methodology there is usually a lot less code. Less code is always a good thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.search-this.com/2010/04/26/asp-net-linq-jquery-json-ajax-oh-my/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>CSS The Star Matrix Pre-loaded: Part 2</title>
		<link>http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/</link>
		<comments>http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 13:19:33 +0000</pubDate>
		<dc:creator>cpradio</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/</guid>
		<description><![CDATA[After reading Paul's article "CSS The Star Matrix Pre-loaded", I wanted to contribute by writing a back-end solution to the CSS effect. Before we get into this, you will need to have PHP 5 installed and MySQL 3.23 or higher. PHP 5 allows for greater implementation of OOP (Object Oriented Programming) than its predecessors. Step [...]]]></description>
			<content:encoded><![CDATA[<p>After reading Paul's article "<a href="http://www.search-this.com/2007/05/23/css-the-star-matrix-pre-loaded/">CSS The Star Matrix Pre-loaded</a>", I wanted to contribute by writing a back-end solution to the CSS effect.</p>
<p>Before we get into this, you will need to have PHP 5 installed and MySQL 3.23 or higher.  PHP 5 allows for greater implementation of OOP (Object Oriented Programming) than its predecessors.</p>
<p><strong>Step 1: Analyze the Project</strong><br />
The first step is always the most crucial, so it should take some thought: What do we want to achieve, and how detailed do we want to get?  All of these are questions that should be asked prior to any coding or any development work.</p>
<p><em>What do we want to achieve and how detailed should we get?</em><br />
In this project, we want to use Paul's CSS technique to build a fully functional rating system.  Ideally, one that does not require any administration.  Everything is automated by pasting a segment of code written in PHP onto a page.</p>
<p>Secondly, we want to ensure that only one IP Address can rate each unique item.  Therefore one person isn't repeatedly clicking on '5 Stars' to throw off the rating average.  Now granted, ensuring a single IP Address is used in rating isn't fool proof.  As those with dial-up connections will likely have a different IP address every time they reconnect, we have to remember our first goal, "does not require any administration!"  No administration means no username and passwords to be assigned.</p>
<p>What about cookies?  Glad you asked; I did think of using cookies to do the tracking, but I figured that would be much easier to overcome than basing it on IP address.  It has become easier to clear the privately stored data in our modern browsers and thus cookies could easily be foiled.</p>
<p>Our third goal is to adequately show the new average rating when clicked without reloading the entire page.  To do this requires the use of AJAX (Asynchronous JavaScript and XML).  In our situation, we will be using more of AJANVP (Asynchronous JavaScript and Name/Value Pairs).  XML can become very bloated and in something like this it's simply unnecessary.  I also considered JSON (JavaScript Object Notation), but again, that has too many dependencies and further complicates the system requirements for this task.  Remember, we are going for no administration and fully automated.</p>
<p>Finally, we want each user to be able to add new ratings without having to insert anything into a database table.  Simply put, the HTML components built should derive the rating data for us.  I'll clear this up later, but you should be excited to know that when we are done you will only need to copy and paste code and the new rating entry will be ready for use.  Nothing more is required.</p>
<p><strong>Step 1 Recap:</strong><br />
In step 1, we answered the questions "What do I want to achieve and how detailed do I want to get?"  The answer can be summarized in these points.</p>
<ol>
<li>Use Paul's CSS Star Matrix technique.</li>
<li>Log the Ratings by IP address to ensure no IP address can rate the same item twice.</li>
<li>Update the Rating seamlessly for the user to see the new average rating.</li>
<li>Make it easy to add new items to rate.</li>
</ol>
<p><strong>Step 2: Designing the Database and Table</strong><br />
Step 2 is designing the storage facility to keep our information. There are a few questions to ask yourself when designing a table like this.  What information do you plan to hold in it?  How do you plan on using the data?</p>
<p><em>What information do I plan to hold in the table?</em></p>
<p>Below is the list of the data we plan to keep track of:</p>
<ul>
<li>Item Name</li>
<li>IP Address</li>
<li>Rating</li>
<li>Date Rated</li>
</ul>
<p>There won't be much use immediately for Date Rated, however, it could be used in the future to build any reports on when each item was rated.</p>
<p><em>How do you plan on using the data?</em></p>
<p>Each item you plan to keep track of should ALWAYS have a use, whether it be immediate or in the future.  For example, Item Name, IP address, and Rating will all be used immediately within this application.  The Item Name will describe the item being rated, the IP address is the IP address of the person rating the item, and Rating, is course their rating for the specific item.  </p>
<p>Date Rated is there for a future use.  It has no immediate use, primarily because it is outside the scope of this project, but as I mentioned before, it could be used to generate reports in the future.</p>
<p><strong>Step 2 Recap:</strong></p>
<p>Here we defined what we will be tracking, how it will be used, and whether it has immediate or future use.  Item Name, IP address, and Rating all have immediate use -- only Date Rated is considered future use.</p>
<p><strong>Step 3: Building the Database and Table</strong><br />
You can opt to create a new Database or use an existing Database; the option is yours and will have no impact on this application.  For those wanting to create a new Database, you can use the following MySQL query (replacing the word 'ratings' with your database name):</p>
<p><code>CREATE DATABASE 'ratings' DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</code></p>
<p>Nothing special about the Database creation, as all of the little details are found in the table.  The table will hold all of the information we described in Step 2 above.</p>
<p><code><br />
CREATE TABLE `rating` (<br />
`item_name` VARCHAR( 20 ) NOT NULL ,<br />
`ip_address` VARCHAR( 15 ) NOT NULL ,<br />
`rating` TINYINT( 1 ) NOT NULL ,<br />
`date_rated` DATE NOT NULL ,<br />
PRIMARY KEY ( `item_name` , `ip_address` )<br />
) ENGINE = MYISAM ;<br />
</code></p>
<p>Notice that the primary keys are "item_name" and "ip_address".  This is to help ensure that no "ip_address" can be used to rate the same "item_name".  Also notice the lengths of each item.  Item Names are not allowed to be more than 20 characters.  If you want to have Item Names that are longer than 20 characters, you will need to alter the above statement with the length you want to use  (up to 255).</p>
<p><strong>Step 3 Recap:</strong><br />
We defined our Database and table so the rating information can be stored.  We set the "item_name" and the "ip_address" columns as our Primary Keys to ensure only one IP address can rate each Item Name.  We also defined the max name length for Item Name as 20.</p>
<p><strong>Step 4: Writing our Rating Class</strong><br />
Strong OOP skills are something to never overlook, as they provide you with clever ways of extending your work in the future, plus they focus entirely on being reusable.  With that said, you may remember my previous articles "<a href="http://www.search-this.com/2007/01/24/oop-in-php-from-a-net-oop-perspective-the-error-class/">OOP in PHP from a .NET OOP Perspective: The Error Class</a>" and "<a href="http://www.search-this.com/2007/02/06/oop-in-php-from-a-net-oop-perspective-the-database-class/">OOP in PHP from a .NET OOP Perspective: The Database Class</a>."  These two articles are going to be used in this project as well.  The Error Class will handle any Database errors we might have, and the Database class will handle the Database connection, Query Execution, etc.</p>
<p>To go any further, you will need to download the following file: <a href='http://www.search-this.com/wp-content/uploads/2007/05/ratingsystem.zip' title='Rating System'><strong>RatingSystem.zip</strong></a></p>
<p>After it has downloaded, extract the contents to your computer.  You should see a 'RatingSystem' folder.  This folder is our example application, go ahead and browse to the RatingSystem &gt; classes folder.</p>
<p>Open the rating.class.php file in any editor.  This is the class that will be used to output the rating information to the page and record a rating by a user.</p>
<p>Now I won't get into all of the code here (you'll have to read those other articles), but I will point out a few things.</p>
<ol>
<li>The first thing you should notice is the OutputRating method.  This method is what loads the CSS technique written by Paul.  If you look at lines 31 and 44, you will see his technique used.  I also made a few modifications to it (of which I hope he does not mind, but I will describe those later).</li>
<li>Next find the RateItem method (approximately line number 66).  This method writes the user's rating to the table.  So if you changed the table name, you will want to update the table name in this method as well.</li>
<li>On line number 111 is the CalculateAverageRating, this method calculates the average rating of an item within the MySQL statement.  Again, if you choose a different table name than described in this article, you will want to update this statement to reflect that change.</li>
<li>Finally, I want to point out line number 170, the CheckRatingsByIp method.  This is the last place you may have to update the table name if you did not use 'rating'.</li>
</ol>
<p><strong>Step 4 Recap:</strong><br />
I provided you with the files to run this rating system and gave key pointers on where the table names may need updated if you opted to use a different name.</p>
<p><strong>Step 5: Setting the Database Connection</strong></p>
<p>To set the database connection open the "include.all.php" file in the "classes" folder.  Notice the line:</p>
<div class="igBar"><span id="lphp-19"><a href="#" onclick="javascript:showPlainTxt('php-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Database::<span style="color:#006600;">Initialize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"mysql"</span>, <span style="color:#FF0000;">"localhost"</span>, <span style="color:#FF0000;">"3306"</span>, <span style="color:#FF0000;">"ratings"</span>, <span style="color:#FF0000;">"username"</span>, <span style="color:#FF0000;">"password"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>  </p>
<p>Replace "ratings" with your database name, username with your database username, and password with your database password.</p>
<p>Once finished, save the file.</p>
<p><strong>Step 6: How to output the Rating information to your page</strong><br />
To display the rating information on your page, you will need to do four things.</p>
<ol>
<li>Place the following snippet at the top of your file (for an example, look at 'rating-example.php' in the RatingSystem folder).</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require_once</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"classes/include.all.php"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>Next you need to have the following in your &lt;head&gt; tags:<br />
<code><br />
&lt;link type="text/css" href="styles/rating.css" rel="stylesheet" media="all" /&gt;<br />
&lt;script type="text/javascript" src="scripts/prototype.js"&gt;&lt;/script&gt;<br />
&lt;script type="text/javascript" src="scripts/rating.js"&gt;&lt;/script&gt;<br />
</code></p>
<p>This code is what sets the stylesheets, AJAX calls, etc. within your page.</li>
<li>Next, find the location you want to output your Rating Stars and paste this code:
<div class="igBar"><span id="lphp-21"><a href="#" onclick="javascript:showPlainTxt('php-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-21">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ratingData</span> = Rating::<span style="color:#006600;">OutputRating</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'demo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Error::<span style="color:#006600;">HasErrors</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> Error::<span style="color:#006600;">ShowErrorMessages</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Error::<span style="color:#006600;">ClearErrors</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$ratingData</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>Finally, end the page with the following code:
<div class="igBar"><span id="lphp-22"><a href="#" onclick="javascript:showPlainTxt('php-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-22">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Database::<span style="color:#006600;">DeInitialize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
</ol>
<p>Replace the word 'demo' with the name of your Item.  If no errors occur, you should see the 5 stars not lit up when you run the page, otherwise, you will see the error messages that occurred.</p>
<p><strong>Step 5 and 6 Recap:</strong><br />
In Step 5 and 6 we entered the Database connection information, and we pasted our code to show the Rating System for a specific item.</p>
<p>That's it!  There isn't anything else needed to get this working.  All you have to do is copy the same snippet of code wherever you want it to appear on your page.  You can have one item to rate on a page, or you can have 10.  Just give them all unique IDs and they can all be on the same page.</p>
<p>Even though you now have a working Rating System, allow me to give you one last walk through of this system.</p>
<p><strong>Crash Course Walk-Through</strong><br />
This walk-through will be based on the "rating-example.php" file from the top-down, not necessarily in processing order.</p>
<p>When your page is loaded, the "classes/include.all.php" file is loaded which establishes your Database connection, initializes the Error class, and allows the Rating class to be used.</p>
<p>Following this, the StyleSheets and JavaScript files are loaded to ensure the Rating System outputs properly and the AJAX capability is setup.</p>
<p>Next the Rating::OutputRating is called to show the rating details of 'demo'.  If an error occurred our error messages are shown, otherwise, it will display the stars lighting up the current rating.</p>
<p>Once the processing is finished, the user will see the page generated.<br />
<img src='http://www.search-this.com/wp-content/uploads/2007/05/rating-system-page.jpg' alt='Rating System Page' width='226' height='148' /></p>
<p>When the user hovers over a rating that they have not rated before, the stars light up appropriately.</p>
<p><img src='http://www.search-this.com/wp-content/uploads/2007/05/rating-system-page-hover.jpg' alt='Rating System Page Hover' width='226' height='148' /></p>
<p>Finally, when the user clicks a star, it is recorded and the average rating is shown to the user with green stars.  Note that even if the user hovers over the stars, they will not light up because they have already cast their vote and rated that item.</p>
<p><img src='http://www.search-this.com/wp-content/uploads/2007/05/rating-system-page-rated.jpg' alt='Rating System Page Rated' width='226' height='148' /></p>
<p>Now this is where I altered Paul's code.  I created a new class called 'rated' (found in the "styles/rating.css") that does not contain the hover effect.  This way if the user already rated an item, they do not the see the hover effect for the item they rated.</p>
<p>When the user clicks on a star, an AJAX event is sent, the rating is calculated, and then the information is returned in a Name/Value pair.  For example, it might return: "item=demo&amp;classes=rated threestar".  Simply put, it means the user clicked on the 'demo' item, and the new classes to use on that item are 'rated' and 'threestar'.  The class "rated" defines the user has rated that item, and no longer provides the hover effect, and the class "threestar" is the average rating for the item, so it is to light up three green stars.</p>
<p><strong>Conclusion:</strong><br />
That ends the task of providing a functional Rating System using Paul's CSS Star Matrix Pre-Loaded technique.  I want to thank Paul for the excellent CSS work, and hopefully I have done it a bit more justice by adding the back-end functionality.</p>
<p>Feel free to leave any comments, remarks, questions, etc. as I will be happy to answer them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Introducing Vinnie Garcia &#8211; aka vinnie</title>
		<link>http://www.search-this.com/2007/01/24/introducing-vinnie-garcia-aka-vinnie/</link>
		<comments>http://www.search-this.com/2007/01/24/introducing-vinnie-garcia-aka-vinnie/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 14:18:40 +0000</pubDate>
		<dc:creator>Golgotha</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Website Design]]></category>

		<guid isPermaLink="false">http://www.search-this.com/2007/01/24/introducing-vinnie-garcia-aka-vinnie/</guid>
		<description><![CDATA[And now, ladies and gentlemen introducing the hardest working man in code business, the one, the only Vinnie Garcia. It's with great pleasure that I introduce Vinnie to the Search-This team. Sure, I had to put a gun to his head, but that's the Italian way of doing things. You may work hard, but no [...]]]></description>
			<content:encoded><![CDATA[<p>
And now, ladies and gentlemen introducing the hardest working man in code business, the one, the only Vinnie Garcia.
</p>
<p>
It's with great pleasure that I introduce Vinnie to the Search-This team. Sure, I had to put a gun to his head, but that's the Italian way of doing things.
</p>
<p>
You may work hard, but no one works harder than Vinnie Garcia. The man is approaching the 20,000 post mark over at the SitePoint forums! And it shows, there's not too many areas in the web world that Vinnie hasn't at least dabbled in. So when Vinnie speaks, you're gonna wanna listen.
</p>
<p>
Enjoy Vinnie's bio below:
</p>
<p><strong>User Name:</strong> vinnie</p>
<ul>
<li><strong>childhood ambition:</strong> becoming a cartoonist</li>
<li><strong>fondest memory:</strong> not sure</li>
<li><strong>favorite music:</strong> anything with a good beat; mostly rock, electronic, and hip-hop</li>
<li><strong>retreat:</strong> the beach or my headphones</li>
<li><strong>proudest moment:</strong> getting married</li>
<li><strong>biggest challenge:</strong> being married <img src='http://www.search-this.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li><strong>alarm clock:</strong> don't use one, I tend to wake up early anyway</li>
<li><strong>perfect day:</strong> sitting by the pool doing nothing at all</li>
<li><strong>first job:</strong> warehouse assistant for a medical supply company</li>
<li><strong>indulgence:</strong> <a href="http://kickball.com/">kickball</a></li>
<li><strong>favorite movie:</strong> lots of them, most recently: Borat</li>
<li><strong>inspiration:</strong> art, nature, architecture, and most importantly loved ones</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.search-this.com/2007/01/24/introducing-vinnie-garcia-aka-vinnie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing Matt Wilkin &#8211; aka cpradio</title>
		<link>http://www.search-this.com/2007/01/12/introducing-matt-wilkin-aka-cpradio/</link>
		<comments>http://www.search-this.com/2007/01/12/introducing-matt-wilkin-aka-cpradio/#comments</comments>
		<pubDate>Sat, 13 Jan 2007 03:19:24 +0000</pubDate>
		<dc:creator>Golgotha</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.search-this.com/2007/01/12/introducing-matt-wilkin-aka-cpradio/</guid>
		<description><![CDATA[Long time users of Search-This will no doubt know cpradio. Matt pretty much grew up on Search-This. When he was just a young lad in high school he was administering the forums and helping people with all their web related needs. Matt's passion has always been as a coder. Now that Matt has graduated college [...]]]></description>
			<content:encoded><![CDATA[<p>
Long time users of Search-This will no doubt know cpradio. Matt pretty much grew up on Search-This. When he was just a young lad in high school he was administering the forums and helping people with all their web related needs.
</p>
<p>
Matt's passion has always been as a coder. Now that Matt has graduated college and become a full time software engineer there's not many languages he hasn't worked with.
</p>
<p>
Look for Matt's, or rather cpradio's first article this Monday titled: "<a href="http://www.search-this.com/2007/01/15/oop-in-php-from-a-net-oop-perspective/">OOP in PHP from a .NET OOP Perspective</a>" - should be a good read.
</p>
<p>
I can't really welcome cpradio as a new member to the team, because he has always been part of the team. So just enjoy his bio below.
</p>
<p><strong>User Name:</strong> cpradio</p>
<ul>
<li><strong>childhood ambition:</strong> to be a software developer, seriously, it was...</li>
<li><strong>fondest memory:</strong> looking at my old code and just realizing what an idiot I was back then</li>
<li><strong>favorite music:</strong> anything but elevator music, seriously, how do you not fall asleep to elevator music?</li>
<li><strong>retreat:</strong> hiking in the smokies</li>
<li><strong>proudest moment:</strong> three weeks of hammering an application, countless thankful users</li>
<li><strong>biggest challenge:</strong> writing quote engines for an insurance company and making it easy to maintain</li>
<li><strong>alarm clock:</strong> 6:30 AM on a good day, 4:30 AM on implementation day (project going to production)</li>
<li><strong>perfect day:</strong> my wife told me it was her wedding day, err... our wedding day. <img src='http://www.search-this.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </li>
<li><strong>first job:</strong> PetsMart stocker/fork-lift driver</li>
<li><strong>indulgence:</strong> hard drives, I have 10 (in one PC) equaling 1.8 TB but that is not enough</li>
<li><strong>favorite movie:</strong> geez, I can't just pick one, that would be unfair to the rest of them</li>
<li><strong>inspiration:</strong> knowing knowledge has no limits other than a person's refusal to continue learning</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.search-this.com/2007/01/12/introducing-matt-wilkin-aka-cpradio/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
