<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Web Design Company in India, Delhi</title>
	<atom:link href="http://expertzweb.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://expertzweb.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 17 Oct 2008 17:29:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='expertzweb.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Web Design Company in India, Delhi</title>
		<link>http://expertzweb.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://expertzweb.wordpress.com/osd.xml" title="Web Design Company in India, Delhi" />
	<atom:link rel='hub' href='http://expertzweb.wordpress.com/?pushpress=hub'/>
		<item>
		<title>AJAX online Examples</title>
		<link>http://expertzweb.wordpress.com/2008/10/17/ajax-online-examples/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/17/ajax-online-examples/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 17:29:22 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax example]]></category>
		<category><![CDATA[ajax tutorial]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=68</guid>
		<description><![CDATA[There are a few special techniques or effects that can spice up just about any web page. These are the top 20 Ajax effects that every web developer should know. They’re essential parts of any web developer’s toolbox. If you haven’t seen them yet, you no doubt will in your future web development endeavors. 1. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=68&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>There are a few special techniques or effects that can spice up just about any web page. These are the top 20 Ajax effects that every web developer should know. They’re essential parts of any web developer’s toolbox. If you haven’t seen them yet, you no doubt will in your future web development endeavors.</div>
<h3>1. TextboxList meets Autocompletion</h3>
<p>Auto-completing fields in a form can be a huge time saver and a major benefit to the user. For example, searching for email addresses is a chore that can easily made much more simple (and I dare say fun) with a splash of Ajax. <a href="http://devthought.com/textboxlist-meets-autocompletion/">TextboxList meets Autocompletion</a> is one such example of an auto-complete script that takes a <a href="http://www.facebook.com/">Facebook</a>-esque approach to autocompletion. The implementation is crisp and useful, not to mention easy on the eyes.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/1.png" alt="" /></div>
<div class="tutorial_image"><a href="http://devthought.com/textboxlist-meets-autocompletion/"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://devthought.com/wp-content/articles/autocompletelist/test.html" target="_blank"><img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>2.Ajax IM</h3>
<p><a href="http://www.ajaxim.com/">Ajax IM</a> is an incredible Ajax instant messenger that works just like <a href="http://messenger.yahoo.com/">Yahoo! messenger</a> or any other IM client, except it’s embedded on the website as opposed to a desktop client. Ajax IM is incredibly robust, and could add quite a bit to your user’s experience. If you’ve got a social networking site or any site where it’s encouraged for users to interact with each other, an IM client could be a great way to increase interaction.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/2.jpg" border="0" alt="" /></div>
<div class="tutorial_image"><a href="http://www.ajaxim.com/"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.ajaxim.net/" target="_blank"><img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>3. LiveValidation</h3>
<p>Web forms can be one of the most frustrating aspects of the Internet. Most are too long and try to collect too much information, and sometimes make it very hard for a valuable user to fill the form out. Possibly one of the <em>most</em> frustrating aspects of filling out a form is hitting “Submit” and getting errors that have to be corrected.</p>
<p>One way to ease the pain of web forms is to add Ajax validation that tells the user instantly when he’s made a mistake. <a href="http://www.livevalidation.com/">LiveValidation</a> is an excellent Ajax script that can make adding Ajax form validation super easy for the developer. A must-have for any project that uses forms.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/3.png" alt="" /></div>
<div class="tutorial_image"><a href="http://www.livevalidation.com/download"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.livevalidation.com/examples" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>4. Inline Editing</h3>
<p>The ability to edit something inline is a small aesthetic feature that can really add to the user’s experience. There’s something much niftier with being able to click a text field and instantly have the ability to edit it.</p>
<p>Manoloweb has a great little Ajax implementation of an <a href="http://www.ideasfreelance.com/lab/instant_edit/">inline editor</a>. It’s a tiny script, but it can be modified to be as simple or complex as you wish.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/4.png" alt="" /></div>
<div class="tutorial_image"><a href="http://www.ideasfreelance.com/lab/instant_edit/remote_cont.js"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.ideasfreelance.com/lab/instant_edit/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>5. Ajax Upload</h3>
<p>Uploading files with Ajax is so much nicer than the boring, old alternative. It’s nice to see the progress of the upload, and it can be much handier for the developer to be able to use Ajax uploads that only modify small sections of the web page.</p>
<p>Because there are many different flavors of Ajax uploading, a simple example that can be added to. AnyExample has a quick and excellent tutorial on how to <a href="http://www.codeproject.com/KB/aspnet/AJAXUpload.aspx">make a basic Ajax upload</a> that you can use as is or expand upon. If you’re looking for an immediate solution, check out jQuery’s <a href="http://plugins.jquery.com/project/jquploader">jqUploader</a> or the <a href="http://www.fyneworks.com/jquery/multiple-file-upload/">multiple file upload scripts</a>.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/5.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://www.codeproject.com/KB/aspnet/AJAXUpload/AJAXUpload_src.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a></div>
<h3>6. Fancy Upload</h3>
<p>Now that we’ve covered the basics for file uploading with Ajax, check out the excellent <a href="http://digitarald.de/project/fancyupload/">Fancy Upload</a>. It’s built off of the excellent Javascript framework <a href="http://mootools.net/">MooTools</a> and can be styled and modified almost endlessly. It’s unobtrusive, can be placed inline and is server independent, so integrating this script to an existing app is relatively easy.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/6.png" alt="" /></div>
<div class="tutorial_image"><a href="http://digitarald.de/project/fancyupload/"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://digitarald.de/project/fancyupload/2-0/showcase/photoqueue/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>7. ClickHeat Clicks Heatmap</h3>
<p>Heatmaps are an underused aspect in web development. While this may not be a wildly-popular feature that your users are begging for, heatmaps are excellent for the developer to see just what the site users are clicking on. While there are plenty of hosted services out there like <a href="http://crazyegg.com/">crazyegg</a>, you can also use your own hosted, Ajax-powered heatmap that’s completely free with <a href="http://www.labsmedia.com/clickheat/index.html">ClickHeat</a>.</p>
<p>ClickHeat is very simple, but also very powerful. It shows who’s clicking on what part of your page in a given date range. This can add plenty of insight as you tweak your layouts for the best performances. <strong>Knowing where your visitors click is absolutely essential information</strong>. You can visually see what ads are performing best, what links people like to click on, and much more data.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/7.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://sourceforge.net/project/showfiles.php?group_id=181196"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.labsmedia.com/clickheat/index.html#" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>8. Ajax Mail Form</h3>
<p>There’s nothing more valuable to a startup or brand new website than a simple form for your visitors to sign up for launch dates and site updates. If you can add Ajax to dynamically process the information, it’s a huge bonus. <a href="http://ninjadesigns.co.uk/">NinjaDesigns</a> has a nifty little PHP script that allows you to add a signup form on your website that uses Ajax to send the information, so a new page isn’t loaded. Extremely valuable for any web developer.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/8.png" alt="" /></div>
<div class="tutorial_image"><a href="http://ninjadesigns.co.uk/enter/mailist.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://ninjadesigns.co.uk/demo/mailist/index.php" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>9. Ajax Directory Manager</h3>
<p>Navigating a traditional hierarchy or folder tree can be quite a pickle for a web user. Each click on a folder requires a page reload, and you can kiss drag-n-drop functionality goodbye. If you want to add a user-friendly directory manager, use Ajax.</p>
<p><a href="http://ecosmear.com/relay/">Relay</a> is a robust directory manager built on ajax that features an interface with features like:</p>
<ul>
<li>drag-n-drop file and folders</li>
<li>dynamically loading file structure</li>
<li>uploads with file progress bar</li>
<li>user accounts</li>
</ul>
<p>.. and more. Relay is totally fully featured, and can be used as a standalone application or a compliment to an existing site.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/9.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://ecosmear.com/relay/download.php"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://ecosmear.com/relay/demo/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>10. Ajax Email Client</h3>
<p>Who doesn’t love <a href="http://www.gmail.com/">Gmail</a>? The email service by Google completely changed the way we use and think about email, and it also forced others like Yahoo! and Hotmail to play catchup and try to compete with Gmail’s features. Google accomplished all of this with a little help from our friend Ajax.</p>
<p>If you wanted to mimic Gmail and create your own Ajax email client, it’s a fun experiment and could be used for many applications. DevArticles has an “oldie but goodie”, a somewhat older but excellent article on <a href="http://www.devarticles.com/c/a/XML/Take-AJAX-to-Your-Email-Inbox-Developing-a-Webbased-POP-3-Client/">how to set up your own Gmail clone</a>.</p>
<h3>11. Improve Form Usability with Auto Messages</h3>
<p>Many of the scripts listed in this article deal with improving user forms, as it’s a big trouble spot for many web developers. The last thing a site owner wants is for people to abandon the website as they’re signing up for the service! If you can make the process of filling out the web form easier, you’ll have a much higher form completion rate.</p>
<p>Using auto messages for forms is an excellent way to give guideposts to the user. Woork has a stellar tutorial on how to <a href="http://woork.blogspot.com/2008/04/improve-form-usability-with-auto.html">add automatic messages to form fields</a>, so that when they’re hovered on a little popup shows below the input. It’s a small feature to add, but huge for improving the user’s experience.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/10.png" alt="" /></div>
<div class="tutorial_image"><a href="http://www.box.net/shared/ez78f38kkk"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a></div>
<h3>12. qGallery</h3>
<p>While it isn’t a full-featured gallery, <a href="http://qgallery.quadrifolia.de/">qGallery</a> is an excellent example of using Ajax to request photos and media. It’s based around the <a href="http://prototypejs.org/">prototype</a> Javascript framework, and it’s a perfect little script for showcasing images. It even has cache functions built in to save bandwidth.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/11.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://qgallery.quadrifolia.de/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>13. Ajax Star Rating</h3>
<p>It seems that people almost always want to give their opinion on something. Having a simple way for users to create ratings is a great way to add interactivity to your website, and also gives the users a “voice”.</p>
<p>There is a simple Ajax script that will do this called the <a href="http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/">unobtrusive ajax start rater</a>. This nifty little script allows users to rate just about anything you specify. It’s not tied to any platform, so you could literally use the script for anything that used PHP and MySQL.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/12.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://www.masugadesign.com/download.php?ajaxstarrater_v122.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>14. CakePHP Ajax Form</h3>
<p>If you’re a user of the web framework like <a href="http://nettuts.com/web-roundups/10-insanely-useful-django-tips/">Django</a> or <a href="http://www.cakephp.org/">CakePHP</a>, you’ll appreciate the tutorial by CakeBaker on how to <a href="http://cakebaker.42dh.com/2006/01/18/submit-a-form-with-ajax/">submit a form with Ajax</a>. It’s actually quite simple to do, and only requires a few lines of code. One especially useful function of this code is that it’s unobtrusive, meaning that if Javascript is disabled in the browser, the form will still submit, just not with Ajax.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/13.jpg" alt="" /></div>
<h3>15. Amberjack Site Tours</h3>
<p>In terms of web developers, <a href="http://www.amberjack.org/">Amberjack</a> is one of the most impressive Javascript libraries to date. Amberjack allows you to quickly and easily create site tours for your users that make using your website less of a mystery. The best part of Amberjack is that the whole library is less than 4kb in size! It’s incredibly easy to customize, and can really make a huge impact on your site visitors with only a little bit of work.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/14.jpg" alt="' /&gt;&lt;/div&gt; &lt;div class=" /> <a href="http://amberjack.org/src/stable/"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://amberjack.org/?tourId=AJTour" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>16. Prototype UI</h3>
<p>Prototype UI takes all of the hard work out of creating visual Ajax elements like carousels and modal windows. The script is based off of <a href="http://www.prototypejs.org/">Prototype</a> and <a href="http://script.aculo.us/">Scriptaculous</a>, and it’s essentially a library of user interface classes. The library is constantly growing, and all of the features are highly skinnable and easy to customize.</p>
<p>It’s always hard to find different libraries for things modal boxes and carousels, so it’s nice when they’re all bundled together.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/15.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://www.prototype-ui.com/download"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.prototype-ui.com/" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>17. JCrop</h3>
<p>Photo editing online is typically a rather involved process. Either you use a service like <a href="http://www.picnik.com/">Picnik</a> or you just fire up ‘ol Photoshop to edit your images. Wouldn’t it be nice if the website allowed you to crop the images that you were uploading?</p>
<p>This is now possible with a <a href="http://www.jquery.com/">jQuery</a> plugin called <a href="http://deepliquid.com/content/Jcrop.html">JCrop</a>. JCrop allows your users to crop any image that’s been uploaded to your servers, using a powerful Ajax cropping engine. Brilliant.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/16.jpg" alt="" /></div>
<div class="tutorial_image"><a href="http://deepliquid.com/content/Jcrop_Download.html"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://deepliquid.com/content/Jcrop_Examples.html" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>18. jQuery Auto-tabbing Plugin</h3>
<p>Like we’ve stated earlier, the job of the web developer is to make filling out forms <em>as easy as possible</em> for the site user. That means adding even the smallest feature if it enhances the user’s experience. One such example is using auto-tabs on things like phone number input fields and social security numbers. Lousyllama has an <a href="http://www.lousyllama.com/sandbox/jquery-autotab">excellent jQuery plugin</a> that allows you to auto-tab form fields that you specify.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/17.png" alt="" /></div>
<div class="tutorial_image"><a href="http://www.lousyllama.com/sites/www.lousyllama.com/files/jquery.autotab-1.1b.js.txt"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.lousyllama.com/sandbox/jquery-autotab" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></div>
<h3>19. Sort Table Rows with Ajax</h3>
<p>Sorting table elements is an incredibly useful feature to have with pages that showcase lots of data. The Daily Inspired has a <a href="http://woork.blogspot.com/2008/02/sort-table-rows-using-ajax.html">nifty tutorial</a> that shows how to achieve this effect with Stuart Langridge’s <a href="http://www.kryogenix.org/code/browser/sorttable/">sortable.js</a>.</p>
<p>Tables are great at organizing data, but being able to further drill-down the information gives your users many more options to viewing the data they way that they want to.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/19.png" alt="" /></div>
<div class="tutorial_image"><a href="http://www.box.net/shared/53al1imrk4"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a></div>
<h3>20. DrasticMap</h3>
<p><a href="http://maps.google.com/">Google Maps</a> is yet another revolutionary product from Google that relies heavily on Ajax to power the site. <a href="http://www.drasticdata.nl/DDDrasticMap.php">DrasticMap</a> is a stellar Javascript/Ajax script that allows you to map coordinates stored in a MySQL database on top of a Google map. It’s highly flexible and configurable, and the possibilities are endless in the ways that it can be used.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/090_20ajax/20.jpg" alt="" /></div>
<p><a href="http://www.drasticdata.nl/DDDownloads.php"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt="" /></a><br />
<a href="http://www.drasticdata.nl/DDExamples.php" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt="" /></a></p>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Web Development Tagged: ajax, ajax example, ajax tutorial <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=68&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/17/ajax-online-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/1.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/2.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/3.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/4.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/5.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/6.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/7.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/8.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/9.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/10.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/11.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/12.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/13.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/14.jpg" medium="image">
			<media:title type="html">&#039; /&#62;&#60;/div&#62; &#60;div class=</media:title>
		</media:content>

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/15.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/16.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/17.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/19.png" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.s3.amazonaws.com/090_20ajax/20.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" medium="image" />

		<media:content url="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" medium="image" />
	</item>
		<item>
		<title>HTACCESS URL Rewriting</title>
		<link>http://expertzweb.wordpress.com/2008/10/12/htaccess-url-rewriting/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/12/htaccess-url-rewriting/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 17:01:19 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.htaccess URL ReWrite]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=65</guid>
		<description><![CDATA[The Apache server’s mod_rewrite module gives you the ability to transparently redirect one URL to another, without the user’s knowledge. This opens up all sorts of possibilities, from simply redirecting old URLs to new addresses, to cleaning up the ‘dirty’ URLs coming from a poor publishing system — giving you URLs that are friendlier to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=65&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="content">
<!-- Intro --></p>
<p>The Apache server’s <code class="unix">mod_<span class="lowlight">rewrite</span></code> module gives you the ability to transparently redirect one URL to another, without the user’s knowledge. This opens up all sorts of possibilities, from simply redirecting old URLs to new addresses, to cleaning up the ‘dirty’ URLs coming from a poor publishing system — giving you URLs that are friendlier to both readers and search engines.</p>
<p><!-- Content Start --></p>
<p><a></p>
<h2 class="heading">An Introduction to Rewriting</h2>
<p>Readable URLs are nice. A well designed website will have a logical file system layout, with smart folder and file names, and as many implementation details left out as possible. In the most well designed sites, readers can <strong>guess at filenames with a high level of success</strong>.</p>
<p>However, there are some cases when the best possible information design can’t stop your site’s URLs from being nigh-on impossible to use. For instance, you may be using a Content Management System that serves out URLs that look something like</p>
<p>http://www.example.com/viewcatalog.asp?category=hats&amp;prodID=53</p>
<p>This is a horrible URL, but it and its brethren are becoming increasingly prevalent in these days of dynamically-generated pages. There are a number of problems with an URL of this kind:</p>
<ul class="wellspaced">
<li>
<p>It <strong>exposes the underlying technology</strong> of the website (in this case <acronym title="[ Active Server Page ] - Microsoft’s dynamic webpage technology" class="help">ASP</acronym>). This can give potential hackers clues as to what type of data they should send along with the query string to perform a ‘front-door’ attack on the site. Information like this shouldn’t be given away if you can help it.</p>
<p>Even if you’re not overly concerned with the security of your site, <strong>the technology you’re using is at best irrelevant</strong> — and at worst a source of confusion — to your readers, so it should be hidden from them if possible.</p>
<p>Also, if at some point in the future you decide to change the language that your site is based on (to <a href="http://php.net/">» PHP</a>, for instance); all your old URLs will stop working. This is a pretty serious problem, as anyone who has tackled a full-on site <span class="lowlight">rewrite</span> will attest.</p>
</li>
<li><strong>The URL is littered with awkward punctuation</strong>, like the question mark and ampersand. Those &amp; characters, in particular, are problematic because if another webmaster links to this page using that URL, the un-escaped ampersands will mess up their <a href="#">XHTML</a> conformance. They will have to laboriously replace all the ampersands with <code>&amp;</code> character entities, which is often forgotten.</li>
<li>Some <strong>search engines won’t index pages which they think are generated dynamically</strong>. They’ll see that question mark in the URL and just turn their asses around.</li>
</ul>
<p>Luckily, using rewriting, we can clean up this URL to something far more manageable. For example, we could map it to</p>
<p>http://www.example.com/catalog/hats/53/</p>
<p>Much better. This URL is more logical, readable and memorable, and will be picked up by all search engines. The <i>faux</i>-directories are short and descriptive. Importantly, it looks more <em>permanent</em>.</p>
<p>To use <code class="unix">mod_<span class="lowlight">rewrite</span></code>, you supply it with the link text you want the server to match, and the real URLs that these URLs will be redirected to. The URLs to be matched can be straight file addresses, which will match one file, or they can be <em>regular expressions</em>, which will match many files.</p>
<p><a></p>
<h2 class="heading">Basic Rewriting</h2>
<p>Some servers will not have <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">» mod_<span class="lowlight">rewrite</span></a> enabled by default. As long as the <a href="http://modules.apache.org/">» module</a> is present in the installation, you can enable it simply by starting a .<span class="lowlight">htaccess</span> file with the command</p>
<p class="code"><code class="unix"><strong><span class="lowlight">Rewrite</span>Engine</strong> on</code></p>
<p>Put this .<span class="lowlight">htaccess</span> file in your root so that rewriting is enabled throughout your site. You only need to write this line once per .<span class="lowlight">htaccess</span> file.</p>
<p><a></p>
<h3 class="subhead">Basic Redirects</h3>
<p>We’ll start off with a straight redirect; as if you had moved a file to a new location and want all links to the old location to be forwarded to the new location. Though you shouldn’t really ever <a title="As Sir Tim says, ‘Cool URIs don’t change’" href="http://www.w3.org/Provider/Style/URI.html">» move a file</a> once it has been placed on the web; at least when you <em>simply have to</em>, you can do your best to stop any old links from breaking.</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Engine</strong> on<br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>old\.html<strong>$</strong>  new.html<br />
</code></p>
<p>Though this is the simplest example possible, it may throw a few people off. The structure of the ‘old’ URL is the only difficult part in this <code class="unix"><span class="lowlight">Rewrite</span>Rule</code>. There are three special characters in there.</p>
<ul class="wellspaced">
<li>The caret, <code class="unix">^</code>, signifies the <strong>start of an URL</strong>, under the current directory. This directory is whatever directory the .<span class="lowlight">htaccess</span> file is in. You’ll start almost all matches with a caret.</li>
<li>The dollar sign, <code class="unix">$</code>, signifies the <strong>end of the string to be matched</strong>. You should add this in to stop your rules matching the first part of longer URLs.</li>
<li>The period or dot before the file extension is a special character in regular expressions, and would mean something special if we didn’t <strong>escape it with the backslash</strong>, which tells Apache to treat it as a normal character.</li>
</ul>
<p>So, this rule will make your server transparently redirect from old.html to the new.html page. Your reader will have no idea that it happened, and it’s pretty much instantaneous.</p>
<p><a></p>
<h3 class="subhead">Forcing New Requests</h3>
<p>Sometimes you <em>do</em> want your readers to know a redirect has occurred, and can do this by forcing a new <abbr title="[ HyperText Transfer Protocol ] - The protocol designed for the Internet, to send webpages" class="help">HTTP</abbr> request for the new page. This will make the browser load up the new page as if it was the page originally requested, and the location bar will change to show the URL of the new page. All you need to do is turn on the <code class="unix">[R]</code> flag, by appending it to the rule:</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>old\.html<strong>$</strong>  new.html <strong>[R]</strong><br />
</code></p>
<p><a></p>
<h2 class="heading">Using Regular Expressions</h2>
<p>Now we get on to the <em>really</em> useful stuff. The power of <code class="unix">mod_<span class="lowlight">rewrite</span></code> comes at the expense of complexity. If this is your first encounter with regular expressions, you may find them to be a tough nut to crack, but the options they afford you are well worth the slog. I’ll be providing plenty of examples to guide you through the basics here. </p>
<p>Using regular expressions you can have your rules matching a set of URLs at a time, and mass-redirect them to their actual pages. Take this rule;</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>products/([0-9][0-9])/<strong>$</strong> /productinfo.php?prodID=$1<br />
</code></p>
<p>This will match any URLs that start with ‘products/’, followed by any two digits, followed by a forward slash. For example, this rule will match an URL like products/12/ or products/99/, and redirect it to the PHP page.</p>
<p>The parts in square brackets are called <em>ranges</em>. In this case we’re allowing anything in the range 0-9, which is any digit. Other ranges would be <code class="unix">[A-Z]</code>, which is any uppercase letter; <code class="unix">[a-z]</code>, any lowercase letter; and <code class="unix">[A-Za-z]</code>, any letter in either case.</p>
<p>We have <strong>encased the regular expression part of the URL in parentheses</strong>, because we want to <strong>store whatever value was found here for later use</strong>. In this case we’re sending this value to a PHP page as an argument. Once we have a value in parentheses we can use it through what’s called a <em>back-reference</em>. <strong>Each of the parts you’ve placed in parentheses are given an index, starting with one</strong>. So, the first back-reference is <code class="unix">$1</code>, the third is <code class="unix">$3</code> etc.</p>
<p>Thus, once the redirect is done, the page loaded in the readers’ browser will be something like productinfo.php?prodID=12 or something similar. Of course, we’re keeping this true URL secret from the reader, because it likely ain’t the prettiest thing they’ll see all day.</p>
<p><a></p>
<h3 class="subhead">Multiple Redirects</h3>
<p>If your site visitor had entered something like products/12, the rule above won’t do a redirect, as the slash at the end is missing. To promote good URL writing, we’ll take care of this by doing a direct redirect to the same URL with the slash appended.</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>products/([0-9][0-9])<strong>$</strong>  /products/$1/ <strong>[R]</strong><br />
</code></p>
<p><strong>Multiple redirects in the same .<span class="lowlight">htaccess</span> file can be applied in sequence</strong>, which is what we’re doing here. This rule is added before the one we did above, like so:</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>products/([0-9][0-9])<strong>$</strong>  /products/$1/ <strong>[R]</strong><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>products/([0-9][0-9])/<strong>$</strong>  /productinfo.php?prodID=$1<br />
</code></p>
<p>Thus, if the user types in the URL products/12, our first rule kicks in, rewriting the URL to include the trailing slash, and doing a new request for products/12/ so the user can see that we likes our trailing slashes around here. Then the second rule has something to match, and transparently redirects this URL to productinfo.php?prodID=12. <em>Slick.</em></p>
<p><a></p>
<h3 class="subhead">Match Modifiers</h3>
<p>You can expand your regular expression patterns by adding some modifier characters, which allow you to match URLs with an indefinite number of characters. In our examples above, we were only allowing two numbers after products. This isn’t the most expandable solution, as if the shop ever grew beyond these initial confines of 99 products and created the URL productinfo.php?prodID=100, our rules would cease to match this URL.</p>
<p>So, instead of hard-coding a set number of digits to look for, we’ll work in some room to grow by allowing any number of characters to be entered. The rule below does just that:</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>products/([0-9]<strong>+</strong>)<strong>$</strong>  /products/$1/ <strong>[R]</strong><br />
</code></p>
<p>Note the plus sign (<code class="unix">+</code>) that has snuck in there. This modifier changes whatever comes directly before it, by saying ‘<strong>one or more of the preceding character or range</strong>.’ In this case it means that the rule will match any URL that starts with products/ and ends with at least one digit. So this’ll match both products/1 and products/1000.</p>
<p>Other match modifiers that can be used in the same way are the asterisk, <code class="unix">*</code>, which means ‘zero or more of the preceding character or range’, and the question mark, <code class="unix">?</code>, which means ‘zero or only one of the preceding character or range.’</p>
<p><a></p>
<h3 class="subhead">Adding Guessable URLs</h3>
<p>Using these simple commands you can set up a slew of ‘shortcut URLs’ that you think visitors will likely try to enter to get to pages they know exist on your site. For example, I’d imagine a lot of visitors try jumping straight into our <a href="#">stylesheets</a> section by typing the URL http://www.yourhtmlsource.com/css/. We can catch these cases, and hopefully alert the reader to the correct address by updating their location bar once the redirect is done with these lines:</p>
<p class="code"><code class="unix"><br />
<strong><span class="lowlight">Rewrite</span>Rule</strong> <strong>^</strong>css(/)?<strong>$</strong> /stylesheets/ <strong>[R]</strong><br />
</code></p>
<p>The simple regular expression in this rule allows it to match the css URL with or without a trailing slash. The question mark means ‘zero or one of the preceding character or range’ — in other words either yourhtmlsource.com/css or yourhtmlsource.com/css/ will both be taken care of by this one rule.</p>
<p>This approach means less confusing <a title="Even if you’ve set up your own, nobody likes to hit them" href="#">404 errors</a> for your readers, and a site that seems to run a whole lot smoother all ’round.</p>
</div>
<br />Posted in Apache, Web Development Tagged: .htaccess URL ReWrite, htaccess <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=65&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/12/htaccess-url-rewriting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
		<item>
		<title>.htaccess Tips and Tricks.</title>
		<link>http://expertzweb.wordpress.com/2008/10/12/htaccess-tips-and-tricks/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/12/htaccess-tips-and-tricks/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 16:54:43 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.htaccess tutorial]]></category>
		<category><![CDATA[.htaccess URL ReWrite]]></category>
		<category><![CDATA[.htacess tips and tricks]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=63</guid>
		<description><![CDATA[&#60;ifModule&#62; more clever stuff here &#60;/ifModule&#62; redirecting and rewriting &#8220;The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.&#8221; - Brian Behlendorf, Apache Group One of the more powerful tricks of the .htaccess [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=63&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="ht-title">&lt;ifModule&gt;</p>
<p><span class="clever">more clever stuff here</span></p>
<p>&lt;/ifModule&gt;</p></div>
<div class="small-space"></div>
<h2>redirecting and rewriting</h2>
<blockquote>
<div id="quote-intro" class="blockquote"><em>&#8220;The great thing about mod_rewrite is it gives you all the<br />
configurability and flexibility of Sendmail. The downside to mod_rewrite is that<br />
it gives you all the configurability and flexibility of Sendmail.&#8221;</em></p>
<div class="right">- Brian Behlendorf, Apache Group</div>
</div>
</blockquote>
<div id="section-intro" class="small-space"></div>
<div id="intro">One of the more powerful tricks of the .htaccess hacker is the ability to rewrite URLs. This enables us to do some mighty manipulations on our links; useful stuff like transforming very long URL&#8217;s into short, cute URLs, transforming dynamic <span class="urltxt">?generated=page&amp;URL&#8217;s</span> into /friendly/flat/links, redirect missing pages, preventing hot-linking, performing automatic language translation, and much, much more.</p>
<p>Make no mistake, mod_rewrite is <em>complex</em>. This isn&#8217;t the subject for a quick bite-size tech-snack, probably not even a week-end crash-course, I&#8217;ve seen guys pull off some real cute stuff with mod_rewrite, but with kudos-hat tipped firmly towards that bastard operator from hell, Ralf S. Engelschall, author of the magic module itself, I have to admit that a great deal of it still seems so much voodoo to me.</p>
<p>The way that rules can work one minute and then seem not to the next, how browser and other in-between network caches interact with rules and testing rules is often baffling, maddening. When I feel the need to bend my mind completely out of shape, I mess around with mod_rewrite!</p>
<p>After all this, it does work, and while I&#8217;m not planning on taking that week-end crash-course any time soon, I have picked up a few wee tricks myself, messing around with webservers and web sites, this place..</p>
<p>The plan here is to just drop some neat stuff, examples, things that have proven useful, and work on a variety of server setups; there are apache&#8217;s all over my LAN, I keep coming across old .htaccess files stuffed with past rewriting experiments that either worked; and I add them to my list, or failed dismally; and I&#8217;m surprised that more often these days, I can <em>see exactly why!</em></p>
<p>Very little here is my own <a id="this-article-MIRRORED-hahahah-worldwide" title="well, okay, a couple of things I did 'invent' - the auto-translation came to me in a dream, and then there's - a limit to anchor titles! ;o)">invention</a>. Even the bits I figured out myself were already well documented, I just hadn&#8217;t understood the documents, or couldn&#8217;t find them. Sometimes, just looking at the same thing from a different angle can make all the difference, so perhaps this humble stab at URL Rewriting might be of some use. I&#8217;m writing it for me, of course. but I do get some credit for this..</p>
<blockquote>
<div id="intro-time-to-get-dynamic" class="blockquote"><code><br />
<span class="code-comment"># time to get dynamic, see..</span></p>
<p>RewriteRule ^(.*)\.htm $1.php</p>
<p></code></div>
</blockquote>
</div>
<div id="section-beginning" class="tiny-space"></div>
<h3>beginning rewriting..</h3>
<div id="beginning">
<p>Whenever you use mod_rewrite (the part of apache that does all this magic), you need to do..</p>
<blockquote>
<div id="rewrite-rule-follow-symlinks" class="blockquote">
<div class="codetop">you only need to do this once per .htaccess file:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p></div>
</div>
</blockquote>
<p>..before any ReWrite rules. <strong>note:</strong> <tt>+FollowSymLinks</tt> <strong>must</strong> be enabled for <em>any</em> rules to work, this is a security requirement of the rewrite engine. Normally it&#8217;s enabled in the root and you shouldn&#8217;t have to add it, but it doesn&#8217;t hurt to do so, and I&#8217;ll insert it into all the examples on this page, just in case*.</p>
<p>The next line simply switches on the rewrite engine<br />
for that folder. if this <a title="any instruction for a server, either in an httpd.conf, a php.ini, or an .htaccess file is called a 'directive'">directive</a> is in you main .htaccess file, then the ReWrite engine is theoretically enabled for your entire site, but it&#8217;s wise to always add that line before you write any redirections, <em>anywhere</em>.</p>
<p><strong>* </strong>Although highly unlikely, your host may have <tt>+FollowSymLinks</tt> enabled at the root level, yet <em>disallow</em> its addition in .htaccess; in which case, adding <tt>+FollowSymLinks</tt> will break your setup (probably a 500 error), so just remove it, and your rules should work fine.</p>
<p><strong>Important:</strong> While some of the directives on this page may appear split onto two lines, in your .htaccess file, they <em>must</em> exist completely on one line. If you drag-select and copy the directives on this page, they should paste just fine into any text editor.</div>
<div id="section-simple_rewriting" class="small-space"></div>
<h3>simple rewriting</h3>
<div id="simple">
<p>Simply put, Apache scans all incoming URL requests, checks for matches in our .htaccess file and rewrites those matching URLs to whatever we specify. something like this..</p>
<blockquote>
<div id="rewrite-rule-htm-to-php" class="blockquote">
<div class="codetop">all requests to whatever.htm will be sent to whatever.php:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.*)\.htm$ $1.php [NC]</p></div>
</div>
</blockquote>
<p>Handy for anyone updating a site from static htm (you could use .html, or .htm(.*), .htm?, etc) to dynamic php pages; requests to the old pages are automatically rewritten to our new urls. no one notices a thing, visitors and search engines can access your content either way. leave the rule in; as an added bonus, this enables us to easily split php code and its included html structures into two separate files, a nice idea; makes editing and updating a breeze. The [NC] part at the end means &#8220;No Case&#8221;, or &#8220;case-insensitive&#8221;, but we&#8217;ll get to the switches later.</p>
<p>Folks can link to whatever.htm or whatever.php, but they always get whatever.php in their browser, and this works even if whatever.htm doesn&#8217;t exist! but I&#8217;m straying..</p>
<p>As it stands, it&#8217;s a bit tricky; folks will still have whatever.htm in their browser address bar, and will still keep bookmarking your old .htm URL&#8217;s. Search engines, too, will keep on indexing your links as .htm, some have even argued that serving up the same content from two different places could have you <em>penalized</em> by the search engines. This may or not bother you, but if it does, mod_rewrite can do some more magic..</p>
<blockquote>
<div id="rewrite-rule-htm-to-php-permanent" class="blockquote">
<div class="codetop">this will do a &#8220;real&#8221; http redirection:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.+)\.htm$ http://corz.org/$1.php [R=301,NC]</p></div>
</div>
</blockquote>
<p>This time we instruct mod_rewrite to send a proper HTTP &#8220;permanently moved&#8221; redirection, aka; &#8220;301&#8243;. Now, instead of just redirecting on-the-fly, the user&#8217;s browser is physically redirected to a new URL, and <span class="urltxt">whatever.php</span> appears in their browser&#8217;s address bar, and search engines and other spidering entities will automatically update their links to the .php versions; everyone wins. and you can take your time with the updating, too.</p>
<p>For details of the many 30* response codes you can send, see <a id="link-http-response-codes" title="Stick with the 300 range!" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">here</a>.</div>
<div id="section-not_so_simple" class="small-space"></div>
<h3>not-so-simple rewriting &#8230; flat links and more</h3>
<div id="not-so-simple">
<p>You may have noticed, the above examples use <em><a title="mod_rewrite uses POSIX standard regular expressions">regular expression</a></em> to match variables. What that simply means is.. match the part inside (.+) and use it to construct &#8220;$1&#8243; in the new URL. In other words, (.+) = $1 you could have multiple (.+) parts and for each, mod_rewrite automatically creates a matching $1, $2, $3, etc, in your target (aka. &#8216;substitution&#8217;) URL. This facility enables us to do all sorts of tricks, and the most common of those, is the creation of &#8220;flat links&#8221;..</p>
<p>Even a cute short link like <span class="urltxt">http://mysite/grab?file=my.zip</span> is too ugly for some people, and nothing less than a true old-school solid <span class="urltxt">domain/path/flat/link</span> will do. Fortunately, mod_rewrite makes it easy to convert URLs with query strings and multiple variables into exactly this, something like..</p>
<blockquote>
<div id="rewrite-rule-with-regex" class="blockquote">
<div class="codetop">a more complex rewrite rule:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^files/([^/]+)/([^/]+).zip /download.php?section=$1&amp;file=$2 [NC]</p></div>
</div>
</blockquote>
<p>would allow you to present this link as..</p>
<p><span class="urltxt"> http://mysite/files/games/hoopy.zip</span></p>
<p>and in the background have that transparently translated, server-side, to..</p>
<p><span class="urltxt"> http://mysite/download.php?section=games&amp;file=hoopy</span></p>
<p>which some script could process. You see, many search engines simply don&#8217;t follow our <span class="urltxt">?generated=links</span>, so if you create generating pages, this is useful. However, it&#8217;s only the dumb search engines that can&#8217;t handle these kinds of links; we have to ask ourselves.. do we really want to be listed by the dumb search engines? <a title="the world's number one search engine" href="http://www.google.com">Google</a> will handle a good few parameters in your URL without any problems, and the (hungry hungry) <a title="many now have .htaccess deny rules in place for this voracious page-guzzler!" href="http://search.msn.com/msnbot.htm">msn-bot</a> stops at nothing to <em>get that page</em>, sometimes again and again and again…</p>
<p>I personally feel it&#8217;s the search engines that should strive to keep up with modern web technologies, in other words; we shouldn&#8217;t have to dumb-down for them. But that&#8217;s just my opinion. Many <em>users</em> will prefer <span class="urltxt">/files/games/hoopy.zip</span> to <span class="urltxt">/download.php?section=games&amp;file=hoopy</span> but I don&#8217;t mind either way. As someone pointed out to me recently, presenting links as <span class="urltxt">standard/flat/paths</span> means you&#8217;re less likely to get folks doing typos in typed URL&#8217;s, so something like..</p>
<blockquote>
<div id="rewrite-rule-more-comlex-regex" class="blockquote">
<div class="codetop">an even more complex rewrite rule:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^blog/([0-9]+)-([a-z]+) http://corz.org/blog/index.php?archive=$1-$2 [NC]</p></div>
</div>
</blockquote>
<p>would be a neat trick, enabling anyone to access my blog archives by doing..</p>
<p><a title="any excuse for an inward link!" href="http://corz.org/blog/2003-nov"><span class="urltxt">http://corz.org/blog/2003-nov</span></a></p>
<p>in their browser, and have it automagically transformed server-side into..</p>
<p><a title="ditto!" href="http://corz.org/blog/index.php?archive=2003-nov"><span class="urltxt">http://corz.org/blog/index.php?archive=2003-nov</span></a></p>
<p>which <a title="drop-in-and-blog blogging software from corz.org" href="/blog/">corzblog</a> would understand. It&#8217;s easy to see that with a little imagination, and a basic understanding of <a title="understanding regex will empower you in ways you would not imagine" href="http://www.google.com/search?q=posix+regular+expression+syntax"><br />
posix regular expression</a>, you can perform some highly cool URL manipulations.</p>
<p>Here&#8217;s the very basics of regexp (expanded from the apache mod_rewrite documentation)..</p>
<div id="section-regexp_basics" class="tiny-space"></div>
<blockquote id="regexp-basics-special-characters">
<div id="rewrite-rule-regexp-special-characters" class="blockquote">
<pre><strong>Escaping:</strong>

<strong>\</strong>char escape that particular char

For instance to specify special characters.. <strong>[].()\</strong> etc.

<strong>Text:</strong>

<strong>.</strong>             Any single character  (on its own = the entire URI)
<strong>[</strong>chars<strong>]</strong>       Character class: One of following chars
<strong>[^</strong>chars<strong>]</strong>      Character class: None of following chars
text1<strong>|</strong>text2   Alternative: text1 or text2 (i.e. "or")

<strong>e.g.</strong> <strong>[^/]</strong> matches any character <em>except</em> <strong>/</strong>
<strong>(foo|bar)\.html</strong> matches <strong>foo.html</strong> <em>and</em> <strong>bar.html</strong>

<strong>Quantifiers:</strong>

<strong>?</strong> 0 or 1 of the preceding text
<strong>*</strong> 0 or N of the preceding text  (hungry)
<strong>+</strong> 1 or N of the preceding text

<strong>e.g.</strong> <strong>(.+)\.html?</strong> matches <strong>foo.htm</strong> <em>and</em> <strong>foo.html</strong>
<strong>(foo)?bar\.html</strong> matches <strong>bar.html</strong> <em>and</em> <strong>foobar.html</strong>

<strong>Grouping:</strong>

<strong>(</strong>text<strong>)</strong>  Grouping of text

Either to set the borders of an alternative or
for making backreferences where the <strong>n</strong>th group can
be used on the target of a RewriteRule with <strong>$n</strong>

<strong>e.g. </strong> ^<strong>(.*)</strong>\.html foo.php?bar=<strong>$1</strong>

<strong>Anchors:</strong>

<strong>^</strong>    Start of line anchor
<strong>$</strong>    End   of line anchor

An anchor explicitly states that the character <em>right next to it</em> MUST
be either the very first character ("^"), or the very last character ("$")
of the URI string to match against the pattern, e.g..

<strong>^foo(.*)</strong> matches <strong>foo</strong> and <strong>foobar</strong> but <em>not</em> <strong>eggfoo</strong>
<strong>(.*)l$</strong> matches <strong>fool</strong> and <strong>cool</strong>, but <em>not</em> <strong>foo</strong></pre>
</div>
</blockquote>
</div>
<div id="section-short_URLs" class="small-space"></div>
<h3>shortening URLs</h3>
<div id="short-urls">
<p>One common use of mod_rewrite is to shorten URL&#8217;s. Shorter URL&#8217;s are easier to remember and, of course, easier to type. An example..</p>
<blockquote>
<div id="rewrite-rule-short-urls" class="blockquote">
<div class="codetop">beware the regular expression:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteRule ^grab(.*) /public/files/download/download.php$1</p></div>
</div>
</blockquote>
<p>this rule would transform this user&#8217;s URL..</p>
<p><span class="urltxt"> http://mysite/grab?file=my.zip</span></p>
<p>server-side, into..</p>
<p><span class="urltxt"> http://mysite/public/files/download/download.php?file=my.zip</span></p>
<p>which is a wee trick I use for my distro machine, among other things. everyone likes short URL&#8217;s, and so will you; using this technique, you can move <span class="urltxt">/public/files/download/</span> to <em>anywhere</em> else in your site, and all the old links still work fine; simply alter your .htaccess file to reflect the new location. edit one line, done &#8211; nice &#8211; means even when stuff is way deep in your site you can have cool links like this..</p>
<p>&lt;!&#8211;<br />
//&lt;![CDATA[<br />
&lt;!<br />
document.write("<a href="\">/trueview/sample.php")<br />
//--&gt;<br />
// --&gt;<br />
// --&gt;<a title="just a simple link (opens in a windoid)" href="OpenWindow('/trueview/php/sample.php',432,460,330,150)">/trueview/sample.php</a><br />
&amp;lt;/p&amp;gt; &amp;lt;div&amp;gt; &amp;lt;a href="/trueview/php/sample.php" mce_href="/trueview/php/sample.php"&amp;gt;&amp;lt;br /&amp;gt; /trueview/php/sample.php&amp;lt;/a&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;p&amp;gt;<br />
and <a id="bbtagslink" title="the corzblog bbcode parser bbcode guide, way deep in the site" href="/bbtags">this</a>; links which are not only short, but <em>flat</em>..</div>
<div id="section-capturing_variables" class="small-space"></div>
<h3>capturing variables</h3>
<div id="capturing-variables">
<p>Slapping <tt>(.*)</tt> onto the end of the request part of a <tt>ReWriteRule</tt> is just fine when using a simple <tt>$_GET</tt> variable, but sometimes you want to do trickier things, like capturing <em>particular</em> variables and converting them into <em>other</em> variables in the target URL. Or something else..</p>
<p>When capturing variables, the first thing you need to know about, is the <tt>[QSA]</tt> flag, which simply tags all the original variables back onto the end of the target url. This may be all you need. The second thing, is <tt>%{QUERY_STRING}</tt>, an Apache server string we can capture variables from, using simple <tt>RewriteCond</tt> (aka. <em>conditional</em> ) statements.</p>
<p>In the following example, the <tt>RewriteCond</tt> statement checks that the query string has the <tt>foo</tt> variable set, and captures its value while it's there. In other words, only requests for <tt>grab</tt> that have the <tt>foo</tt> variable set, will be rewritten, and while we're at it, we'll also switch <tt>foo</tt>, for <tt>bar</tt>..</p>
<blockquote>
<div id="simple-capture-variables" class="blockquote">
<div class="codetop">capturing a $_GET variable:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteCond %{QUERY_STRING} foo=(.*)</p>
<p>RewriteRule ^grab(.*) /page.php?bar=%1</p></div>
</div>
</blockquote>
<p>would translate a link/user's request for..</p>
<p><tt>http://domain.com/grab?foo=foobar</tt></p>
<p>server-side, into..</p>
<p><tt>http://domain.com/page.php?bar=foobar</tt></p>
<p>Which is to say, the user's browser would be fed <tt>page.php</tt> (without an <tt>[R]</tt> flag in the <tt>RewriteRule</tt>, their address bar would still read <tt>/grab?foo=foobar</tt>). The variable <tt>bar</tt> would be available to your script, with its value set to <tt>foobar</tt>.</p>
<p>This variable has been magically created, by simply using a regular <tt><strong>?</strong></tt> in the target of the <tt>RewriteRule</tt>, and tagging on the first captured backreference, <strong>%1</strong>.. <tt>?bar=%1</tt></p>
<p><strong>Note</strong> how we use the <code><strong>%</strong></code> character, to specify variables captured in <tt>RewriteCond</tt> statements, aka "Backreferences". This is exactly like using <strong>$1</strong> to specify numbered backreferences captured in <tt>RewriteRule</tt> patterns, except for those captured inside <tt>RewriteCond</tt> statements, we use <code><strong>%</strong></code> instead of <strong>$</strong>.</p>
<p>You can use the <tt>[QSA]</tt> flag in addition to these query string manipulations, merge them. In the next example, the value of <tt>foo</tt> becomes the <em>directory</em> in the target URL, the variable <tt>file</tt> is magically created, and the original query string is then tagged back onto the end of the whole thing..</p>
<blockquote>
<div id="more-complex-variable-capture" class="blockquote">
<div class="codetop">QSA Overkill!</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteCond %{QUERY_STRING} foo=(.+)</p>
<p>RewriteRule ^grab/(.*) /%1/index.php?file=$1 [QSA]</p></div>
</div>
</blockquote>
<p>So a request for..</p>
<p><tt>http://domain.com/grab/foobar.zip?level=5&amp;foo=bar</tt></p>
<p>is translated, server-side, into..</p>
<p><tt>http://domain.com/bar/index.php?file=foobar.zip&amp;level=5&amp;foo=bar</tt></p>
<p>Depending on your needs, you could even use flat links <em>and</em> dynamic variables together, something like this could be useful..</p>
<blockquote>
<div id="variable-capture-mix-flat-and-dynamic-links" class="blockquote">
<div class="codetop">mixing flat and dynamic links in a single ruleset..</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteCond %{QUERY_STRING} version=(.+)</p>
<p>RewriteRule ^grab/([^/]+)/(.*) /%1/index.php?section=$1&amp;file=$2 [QSA]</p></div>
</div>
</blockquote>
<p>By the way, you can easily do the <em>opposite</em>, strip a query string from a URL, by simply putting a <tt><strong>?</strong></tt> right at the end of the taget part. This example does exactly that, whilst leaving the actual URI intact..</p>
<blockquote>
<div id="strip-variables" class="blockquote">
<div class="codetop">just a demo!</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteCond %{QUERY_STRING} .</p>
<p>RewriteRule foo.php(.*) /foo.php<strong>?</strong> [L]</div>
</div>
</blockquote>
<p>The <tt>RewriteCond</tt> statement only allows requests that have <em>something</em> in their query string, to be processed by the <tt>RewriteRule</tt>, or else we'd end up in that hellish place, dread to all mod_rewriters.. the endless loop. <tt>RewriteCond</tt> is often used like this; as a safety-net.</div>
<div id="section-cooler_access_denied" class="small-space"></div>
<h3>cooler access denied</h3>
<div id="cooler-access-denied">
<p>In <a title="authentication, indexing, and more" href="htaccess.php#denied">part one</a> I<br />
demonstrated a drop-dead simple mechanism for denying access to particular files and folders. The trouble with<br />
this is the way our user gets a 403 "Access Denied" error, which is a bit like having a door slammed in your face.<br />
Fortunately, mod_rewrite comes to the rescue again and enables us to do less painful things. One method I often<br />
employ is to redirect the user to the parent folder..</p>
<blockquote>
<div id="rewrite-rule-cool-access-denied" class="blockquote">
<div class="codetop">they go "huh?.. ahhh!"</div>
<div class="codeblock"><span class="code-comment"># send them up!</span></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.*)$ ../ [NC]</p></div>
</div>
</blockquote>
<p>It works great, though it can be a wee bit tricky with the URLs, and you may prefer to use a harder location, which avoids potential issues in indexed directories, where folks can get in a loop..</p>
<blockquote>
<div id="rewrite-rule-cooler-access-denied" class="blockquote">
<div class="codetop">they go damn! Oh!</div>
<div class="codeblock"><span class="code-comment"># send them exactly there!</span></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.*)$ /comms/hardware/router/ [NC]</p></div>
</div>
</blockquote>
<p>Sometimes you'll only want to deny access to <em>most</em> of the files in the directory, but allow access to maybe one or two files, or file types, easy..</p>
<blockquote>
<div id="rewrite-rule-deny-with-style" class="blockquote">
<div class="codetop">deny with style!</div>
<div class="codeblock"><span class="code-comment"># users can load only "special.zip", and the css and js files.</span></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine On</p>
<p>RewriteCond %{REQUEST_FILENAME} !^(.+)\.css$</p>
<p>RewriteCond %{REQUEST_FILENAME} !^(.+)\.js$</p>
<p>RewriteCond %{REQUEST_FILENAME} !special.zip$</p>
<p>RewriteRule ^(.+)$ /chat/ [NC]</p></div>
</div>
</blockquote>
<p>Here we take the whole thing a stage further. Users can access .css (stylesheet) and javascript files without problem, and also the file called "special.zip", but requests for any other filetypes are immediately redirected back up to the main "/chat/" directory. You can add as many types as you need. You could also bundle the filetypes into one line using | (or) syntax, though individual lines are perhaps clearer.</p>
<p>Here's what's currently cooking inside my <tt>/inc/</tt> directory..</p>
<blockquote>
<div id="rewrite-rule-control-inc" class="blockquote">
<div class="codetop">all-in-one control..</div>
<div class="codeblock">RewriteEngine on</p>
<p>Options +FollowSymlinks</p>
<p><span class="code-comment"># allow access with no restrictions to local machine at 192.168.1.3</span></p>
<p>RewriteCond %{REMOTE_ADDR} !192.168.1.3</p>
<p><span class="code-comment"># allow access to all .css and .js in sub-directories..</span></p>
<p>RewriteCond %{REQUEST_URI} !\.css$</p>
<p>RewriteCond %{REQUEST_URI} !\.js$</p>
<p><span class="code-comment"># allow access to the files inside img/, but not a directory listing..</span></p>
<p>RewriteCond %{REQUEST_URI} !img/(.*)\.</p>
<p><span class="code-comment"># allow access to these particular files...</span></p>
<p>RewriteCond %{REQUEST_URI} !comments.php$</p>
<p>RewriteCond %{REQUEST_URI} !corzmail.php$</p>
<p>RewriteCond %{REQUEST_URI} !digitrack.php$</p>
<p>RewriteCond %{REQUEST_URI} !gd-verify.php$</p>
<p>RewriteCond %{REQUEST_URI} !post-dumper.php$</p>
<p>RewriteCond %{REQUEST_URI} !print.php$</p>
<p>RewriteCond %{REQUEST_URI} !source-dump.php$</p>
<p>RewriteCond %{REQUEST_URI} !textview.php$</p>
<p>RewriteRule ^(.*)$ / [R,nc,l]</p></div>
</div>
</blockquote>
</div>
<div id="section-prevent_hot-linking" class="small-space"></div>
<h3>prevent hot-linking</h3>
<div id="h0t71nKiN4_FuCkP1g5">
<p>Believe it or not, there are some webmasters who, rather than coming up with their own content will <em>steal</em> yours. Really! Even worse, they won't even bother to copy to their own server to serve it up, they'll just <strong>link to your content!</strong> no, it's true, in fact, it used to be incredibly common. These days most people like to prevent this sort of thing, and .htaccess is one of the best ways to do it.</p>
<p>This is one of those directives where the mileage variables are at their limits, but something like this works fine for me..</p>
<blockquote>
<div id="rewrite-rule-prevent-hot-linking" class="blockquote">
<div class="codetop">how DARE they!</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p><span class="code-comment"># no hot-linking</span></p>
<p>RewriteEngine On</p>
<p>RewriteCond %{HTTP_REFERER} !^$</p>
<p>RewriteCond %{HTTP_REFERER} !^http://(www\.)?corz\.org/ [NC]</p>
<p>RewriteRule .*\.(gif|jpg|png)$<br />
&lt;!--<br />
//&lt;![CDATA[<br />
&lt;!<br />
document.write("<a href="\">http://corz.org/img/hotlink.png  [NC]")<br />
//--&gt;<br />
// --&gt;<br />
// --&gt;<a title="this is what you get hot-linking to corz.org!" href="OpenWindow('/img/hotlink.png',233,20,370,200)">http://corz.org/img/hotlink.png</a> [NC]<br />
&amp;lt;/p&amp;gt; &amp;lt;div&amp;gt; &amp;lt;a href="/img/hotlink.png" mce_href="/img/hotlink.png" title="(opens in a new window - apple-click (shift-click on peecees) for a new tab instead)"&amp;gt;&amp;lt;br /&amp;gt; http://corz.org/img/hotlink.png&amp;lt;/a&amp;gt;  [NC]&amp;lt;br /&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;p&amp;gt;</div>
</div>
</blockquote>
<p>You may see the last line broken into two, but it's all one line (all the directives on this page are). Let's have a wee look at what it does..</p>
<p>We begin by enabling the rewrite engine, as always.</p>
<p>The first <a title="'conditions', things to and match against the rewrite rule with deal with whatever requests these 'conditions' match">RewriteCond</a> line allows <em>direct</em> requests (not <em>from</em> other pages - an "empty referrer") to pass unmolested. The next line means; <em>if</em> the browser <em>did</em> send a referrer header, and the word "corz.org" is <em>not in the domain part of it</em>, then <em>DO</em> rewrite this request.</p>
<p>The all-important final <a title="the magic happens here. only requests that got through all the condition statements will be processed by the rule on this line.">RewriteRule</a> line instructs mod_rewrite to rewrite all matched requests (anything without "corz.org" in its referrer) asking for gifs, jpegs, or pngs, to an alternative image. Mine says "no hotlinking!" You can see it in action <a title="handy directory viewer, if the target webmaster is dumb" href="http://www.opendirviewer.nl/?url=http%3A%2F%2Fcorz.org%2Fpublic%2Fimages%2F&amp;submit=Go&amp;pagecount=20">here</a>.</p>
<p>There are loads of ways you can write this rule. google for "hot-link protection" and get a whole heap. Simple is best. You could send a wee message instead, or direct them to some evil script, or something. These days, mine is a simple <tt>corz.org</tt> logo, which <em>I</em> think is rather clever.</div>
<div id="section-lose_the_www" class="small-space"></div>
<h3>lose the "www"</h3>
<div id="NOWWW">
<p>I'm often asked how I prevent the "www" part showing up at my site, so I guess I should add something about that. Briefly, if someone types http://www.corz.org/ into their browser (or uses the www part for any link at corz.org) it is redirected to the plain, rather neat, http://corz.org/ version. This is <em>very</em> simple to achieve, like this..</p>
<blockquote>
<div id="rewrite-rule-no-www" class="blockquote">
<div class="codetop">beware the regular expression:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteCond %{http_host} ^www\.corz\.org [NC]</p>
<p>RewriteRule ^(.*)$ http://corz.org/$1 [R=301,NC]</p></div>
</div>
</blockquote>
<p>You don't need to be a genius to see what's going on here. There are other ways you could write this rule, but again, simple is best. Like most of the examples here, the above is pasted directly from my own main .htaccess file, so you can be sure it works perfectly. In fact, I recently updated it so that I could share rules between my dev mirror and live site without any .htaccess editing..</p>
<blockquote>
<div id="rewrite-rule-no-www-better" class="blockquote">
<div class="codetop">here's what I'm currently using:</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteCond %{HTTP_HOST}  ^www\.(.*) [NC]</p>
<p>RewriteRule ^(.*)$  http://%1/$1 [R=301,NC,L]</p></div>
</div>
</blockquote>
</div>
<div id="section-rewrite_sub-domains" class="small-space"></div>
<h3>multiple domains in one root</h3>
<div id="mod_rewrite-domains">
<p>If you are in the unfortunate position of having your sites living on a host that doesn't support multiple domains, you may be forced to roll your own with <tt>.htaccess</tt> and <tt>mod_rewrite</tt>. So long as your physical directory structure is well thought-out, this is fairly simple to achieve.</p>
<p>For example, let's say we have two domains, pointing at a single hosted root; <tt>domain-one.com</tt> and <tt>domain-two.com</tt>. In our web server root, we simply create a folder for each domain, perhaps <tt>one/</tt>, and <tt>two/</tt> then in our main (root) <tt>.htaccess</tt>, rewrite all incoming requests, like this..</p>
<blockquote>
<div class="blockquote">
<div class="codetop">All requests NOT already rewritten into these folders, transparently rewrite..</div>
<div class="codeblock"><code><span class="php-comment">#two domains served from one root..</span></p>
<p>RewriteCond %{HTTP_HOST} domain-one.com</p>
<p>RewriteCond %{REQUEST_URI} !^/one</p>
<p>RewriteRule ^(.*)$  one/$1 [L]</p>
<p>RewriteCond %{HTTP_HOST} domain-two.com</p>
<p>RewriteCond %{REQUEST_URI} !^two</p>
<p>RewriteRule ^(.*)$  two/$1 [L]</p>
<p></code></div>
</div>
</blockquote>
<p>All requests for the host <tt>domain-one.com</tt> are rewritten (not R=redirected) to the <tt>one/</tt> directory, so long as they haven't already been rewritten there (the second <tt>RewriteCond</tt>). Same story for <tt>domain-two.com</tt>. Note the inconsistency in the RewriteCond statement; <tt>!^/dir-name</tt> and <tt>!^dir-name</tt> should both work fine.</p>
<p>Also note, with such a simple domain &amp; folder naming scheme, you could easily merge these two rule sets together. This would be unlikely in the real world though, which is why I left them separate; but still, worth noting.</p>
<p>Other general settings and php directives can also go in this root <tt>.htaccess</tt> file, though if you have any further rewrite you'd like to perform; short URL's, htm to php conversion and what-not; it's probably easier and clearer to do those inside the sub-directory's .htaccess files.</div>
<div id="section-auto-translation" class="tiny-space"></div>
<h3>automatic translation</h3>
<div id="auto-translate">If you don't read English, or some of your guests don't, here's a neat way to have the wonderful Google translator provide automatic on-the-fly translation for your site's pages. Something like this..</p>
<blockquote>
<div id="rewrite-rule-auto-translation-ORIGINAL" class="blockquote">
<div class="codetop">they simply add their country code to the end of the link, or <em>you</em> do..</div>
<div class="codeblock">Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.*)-fr$  http://www.google.com/translate_c?hl=fr&amp;sl=en&amp;u=http://corz.org/$1 [R,NC]</p>
<p>RewriteRule ^(.*)-de$  http://www.google.com/translate_c?hl=de&amp;sl=en&amp;u=http://corz.org/$1 [R,NC]</p>
<p>RewriteRule ^(.*)-es$  http://www.google.com/translate_c?hl=es&amp;sl=en&amp;u=http://corz.org/$1 [R,NC]</p>
<p>RewriteRule ^(.*)-it$  http://www.google.com/translate_c?hl=it&amp;sl=en&amp;u=http://corz.org/$1 [R,NC]</p>
<p>RewriteRule ^(.*)-pt$  http://www.google.com/translate_c?hl=pt&amp;sl=en&amp;u=http://corz.org/$1 [R,NC]</p></div>
</div>
</blockquote>
<p>You can create your menu with its flags or whatever you like, and add the country code to end of the links.. <tt><a id="... &lt;/tt&gt; &lt;a id=" title="Automatic Translation courtesy of the ever-wonderful Google" rel="nofollow" href="page.html-fr">Want to see this page in French</a>?</p>
<p></tt></p>
<p><tt>Although it is very handy, and I've been using it here for a couple of years here at the org, for my international blog readers, all two of them, heh. Almost no one knows about it, mainly because I don't have any <em>links</em> . One day I'll probably do a wee toolbar with flags and what-not. Perhaps not. Trouble is, the Google translator stops translating after a certain amount of characters (which seems to be increasing, good), though these same rules could easily be applied to other translators, and if you find a good one, one that will translate a really <em>huge</em> document on-the-fly, do let me know!</p>
<p></tt></p>
<p><tt>If you wanted to be really clever, you could even perform some some kind of IP block check and present the correct version automatically, but that is outside the scope of this document. note: this may be undesirable for pages where technical commands are given (like this page) because the commands will also be translated. "RewriteEngine dessus" will almost certainly get you a 500 error page!</p>
<p></tt></div>
<div class="small-space"><tt> </tt></div>
<h3><tt>httpd.conf</tt></h3>
<div id="subfolderrulesok">
<p><tt>Remember, if you put these rules in the main server conf file (usually httpd.conf) rather than an .htaccess file, you'll need to use <strong>^/...</strong> ... instead of <strong>^...</strong> ... at the beginning of the RewriteRule line, in other words, add a slash.<br />
</tt></div>
<div id="section-inheritance" class="small-space"><tt> </tt></div>
<p><tt><br />
</tt></p>
<h3><tt>inheritance..</tt></h3>
<div id="inheritance">
<p><tt>If you are creating rules in sub-folders of your site, you need to read this.</p>
<p></tt></p>
<p><tt>You'll remember how rules in top folders apply to all the folders <em>inside</em> those folders too. we call this "inheritance". normally this just works. <strong>but</strong> if you start creating other rules inside subfolders you will, in effect, obliterate the rules already applying to that folder due to inheritance, or "decendancy", if you prefer. not <em>all</em> the rules, <em>just the ones applying to that subfolder</em>. a wee demonstration..</p>
<p></tt></p>
<p><tt>Let's say I have a rule in my main <code>/.htaccess</code> which redirected requests for files ending .htm to their .php equivalent, just like the example at the top of this very page. now, if for any reason I need to add some rewrite rules to my <code>/osx/.htaccess</code> file, the .htm &gt;&gt; .php redirection will no longer work for the <code>/osx/</code> subfolder, I'll need to reinsert it, <em>but with a <span style="color:#f81d00;">crucial</span> difference</em>..</p>
<p></tt></p>
<blockquote>
<div id="rewrite-rule-inheritance-cascading" class="blockquote">
<div class="codetop"><tt>this works fine, site-wide, in my main .htaccess file </tt></div>
<div class="codeblock"><span class="code-comment"><tt># main (top-level) .htaccess file..</tt></span><tt></p>
<p><span class="code-comment"># requests to file.htm goto file.php</span></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule ^(.*)\.htm$ http://corz.org/$1.php [R=301,NC]<br />
</tt></div>
</div>
</blockquote>
<p><tt><br />
</tt></p>
<p><tt>Here's my updated <code>/osx/.htaccess</code> file, with the .htm &gt;&gt; .php redirection rule reinserted..</p>
<p></tt></p>
<blockquote>
<div id="rewrite-rule-subfolder-rules" class="blockquote">
<div class="codetop"><tt>but I'll need to reinsert the rules for it to work in this sub-folder </tt></div>
<div class="codeblock"><span class="code-comment"><tt># /osx/.htaccess file..</tt></span><tt></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p>RewriteRule some rule that I need here</p>
<p>RewriteRule some other rule I need here</p>
<p>RewriteRule ^(.*)\.htm$ http://corz.org/<span style="color:#f81d00;">osx/</span>$1.php [R=301,NC]<br />
</tt></div>
</div>
</blockquote>
<p><tt><br />
</tt></p>
<p><tt>Spot the difference in the subfolder rule, highlighted in <span style="color:#f81d00;">red</span>. you <strong>must</strong> add the current path to the new rule. now it works again, and all the osx/ subfolders will be covered by the new rule. if you remember this, you can go replicating rewrite rules all over the place.</p>
<p></tt></p>
<p><tt>If it's possible to put your entire site's rewrite rules into the main .htaccess file, and it probably is; do that, instead, like this..</p>
<p></tt></p>
<blockquote>
<div id="rewrite-rule-all-in-one" class="blockquote">
<div class="codetop"><tt>it's a good idea to put all your rules in your main .htaccess file.. </tt></div>
<div class="codeblock"><span class="code-comment"><tt># root /.htaccess file..</tt></span><tt></p>
<p>Options +FollowSymlinks</p>
<p>RewriteEngine on</p>
<p><span class="code-comment"># .htm &gt;&gt; .php is now be covered by our main rule, there's no need to repeat it. </span></p>
<p><span class="code-comment"># But if we do need some /osx/-specific rule, we can do something like this..</span></p>
<p>RewriteRule ^<span style="color:#f81d00;">osx/</span>(.*)\.foo$ <a title="normally, there's no need to specify the full URL.">/</a><span style="color:#f81d00;">osx/</span>$1.bar [R=301,NC]<br />
</tt></div>
</div>
</blockquote>
<p><tt><br />
</tt></p>
<p><tt>Note, no full URL (with domain) in the second example. Don't let this throw you; with or without is functionally identical, on <em>most</em> servers. Essentially, try it without the full URL first, and if that doesn't work, sigh, and add it - maybe on your next host!</p>
<p></tt></p>
<p><tt>The latter, simpler form is preferable, if only for its tremendous portability it offers - my live site, and my development mirror share the exact same .htaccess files - a highly desirable thing.</p>
<p></tt></p>
<p><tt>By the way, it perhaps doesn't go without saying that if you want to <em>disable</em> rewriting inside a particular subfolder, where it is <em>enabled</em> further up the tree, simply do:</p>
<p></tt></p>
<blockquote>
<div id="rewrite-rule-disable-rewriting-in-here" class="blockquote">
<div class="codetop"><tt>handy for avatar folders, to allow hot-linking, etc.. </tt></div>
<div class="codeblock"><tt>RewriteEngine <a id="mod_rewrite_OFF" title="using 'on', would also work, but with a slight performance penalty. Also, it's  silly.">off</a> </tt></div>
</div>
</blockquote>
</div>
<div id="section-conclusion" class="small-space"><tt> </tt></div>
<p><tt><br />
</tt></p>
<h3><tt>conclusion</tt></h3>
<div id="summinup">
<p><tt>In short, mod_rewrite allows you to send browsers <em>from</em> anywhere <em>to anywhere</em>. You can create rules based not simply on the requested URL, but also on such things as IP address, browser agent (send old browsers to different pages, for instance), and even the time of day; the possibilities are practically limitless.</p>
<p></tt></p>
<p><tt>The ins-and outs of mod_rewrite syntax are topic for a <em>much</em> longer document than this, and if you fancy experimenting with more advanced rewriting rules, I urge you to check out the apache documentation.</p>
<p></tt></p>
<p><tt>If you have apache installed on your system, there will likely be a copy of the apache manual, <a title="oh what a clever puter you've got! (opens in a new window - apple-click (shift-click on peecees) for a new tab instead)" href="http://localhost/manual/">right here</a>, and the excellent mod_rewriting guide, <a title="aye, there's loads of stuff like this hidden in yer puter! (opens in a new window - apple-click (shift-click on peecees) for a new tab instead)" href="http://localhost/manual/misc/rewriteguide.html">lives right here</a>. do check out the <a title="the syntax stuff lives here (opens in a new window - apple/shift-click for a new tab/window)" href="http://localhost/manual/mod/mod_rewrite.html">URL Rewriting Engine notes</a> for the juicy syntax bits. That's where I got the cute quote for the top of the page, too.<br />
</tt></div>
<div class="small-space"><tt> </tt></div>
<div id="ceeya"><tt>;o)</p>
<p><a href="mailto:corz@corz.org?subject=htaccess2.php">(or</a><br />
</tt></div>
<div class="quarter-space"><tt> </tt></div>
<div id="section-troubleshooting" class="tiny-space"><tt> </tt></div>
<p><tt><br />
</tt></p>
<h3><tt>troubleshooting tips..</tt></h3>
<div id="troubleshooting">
<h4><tt>rewrite logging..</tt></h4>
<p><tt>When things aren't working, you may want to enable rewrite logging. I'll assume you are testing these mod_rewrite directives on your development mirror, or similar setup, and can access the main <tt>httpd.conf</tt> file. If not, <em>why not?</em> Testing <tt>mod_rewrite</tt> rules on your live domain isn't exactly ideal, is it? Anyway, put this somewhere at the foot of your <tt>http.conf</tt>..</p>
<p></tt></p>
<blockquote>
<div id="rewrite-rule-logging" class="blockquote">
<div class="codetop"><tt>Expect large log files.. </tt></div>
<div class="codeblock"><span class="code-comment"><tt>#</tt></span><tt></p>
<p><span class="code-comment"># ONLY FOR TESTING REWRITE RULES!!!!!</span></p>
<p><span class="code-comment">#</span></p>
<p>RewriteLog "/tmp/rewrite.log"</p>
<p><span class="code-comment">#RewriteLogLevel 9</span></p>
<p>RewriteLogLevel 5<br />
</tt></div>
</div>
</blockquote>
<p><tt><br />
</tt></p>
<p><tt>Set the file location and logging level to suit your own requirements.</tt></p>
<p><tt>If your rule is causing your Apache to loop, load the page, immediately hit your browser's "STOP" button, and then restart Apache. All within a couple of seconds. Your rewrite log will be full of all your diagnostic information, and your server will carry on as before.</p>
<p>Setting a value of 1 gets you almost no information, setting the log level to 9 gets you GIGABYTES!  So you <strong>must</strong> remember to comment out these rules and restart Apache when you are finished because, not only will rewrite logging create space-eating files, it will seriously impact your web server's performance.</p>
<p></tt></p>
<p><tt><tt>RewriteLogLevel 5</tt> is very useful, I find.</p>
<p></tt></p>
<h4><tt>Fatal Redirection</tt></h4>
<p><tt>If you start messing around with 301 redirects [R=301], aka. "Permanently Redirected", and your rule isn't working, you could give yourself some serious headaches..</p>
<p></tt></p>
<p><tt>Once the browser has been redirected <em>permanently</em> to the wrong address, if you then go on to alter the wonky rule, your browser will <em>still</em> be redirected to the old address (because it's a browser thing), and you may even go on to fix, <em>and then break</em> the rule all over again without ever knowing it. Changes to 301 redirects can take a long time to show up in your browser.</p>
<p></tt></p>
<p><tt><strong>Solution</strong>: restart your browser, or use a different one.</p>
<p></tt></p>
<p><tt><strong>Better Solution</strong>: Use [R] instead of [R=301] <em>while you are testing</em> . When you are 100% certain the rule does exactly as it's expected to, <em>then</em> switch it to [R=301] for your live site.<br />
</tt></p>
<div id="section-debug-report.php" class="tiny-space"><tt> </tt></div>
<p><tt><br />
</tt></p>
<h4><tt><big><tt>debug-report.php</tt></big></p>
<p>A php script to make your mod_rewrite life easier!</tt></h4>
<p><tt>When things aren't working as you would expect, you probably won't have to enable rewrite logging to get the information you need. What's usually required is no more than a quick readout of all the current variables, <tt>$_GET</tt> array, and so on; so you can see <em>exactly</em> what happened to the request.</p>
<p></tt></p>
<p><tt>For another purpose, I long ago created <tt>debug.php</tt>, and later, finding all this information useful in chasing down wonky rewrites, created a "report" version, which rather than output to a file, spits the information straight back into your browser, as well as <tt>$_POST</tt>, <tt>$_SESSION</tt>, and <tt>$_SERVER</tt> arrays, special variables, like <tt>__FILE__</tt>, and much more.</p>
<p></tt></p>
<p><tt>Usage is simple; you make it your <em>target page</em>, so in a rule like this..</p>
<p></tt></p>
<blockquote>
<div id="test-your-rules-with-debug-report-php" class="blockquote">
<div class="codeblock"><tt>RewriteRule ^(.*)\.html$ /catch-all.php?var=$1<br />
</tt></div>
</div>
</blockquote>
<p><tt><br />
</tt></div>
<div><tt>Posted By: <a href="http://www.expertzweb.com">ExpertzWeb</a></tt></div>
<br />Posted in Apache, Web Development Tagged: .htaccess tutorial, .htaccess URL ReWrite, .htacess tips and tricks <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=63&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/12/htaccess-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
		<item>
		<title>37 More Shocking jQuery Plugins</title>
		<link>http://expertzweb.wordpress.com/2008/10/11/37-more-shocking-jquery-plugins/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/11/37-more-shocking-jquery-plugins/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 18:45:52 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java plugins]]></category>
		<category><![CDATA[java script]]></category>
		<category><![CDATA[java script plugins]]></category>
		<category><![CDATA[java script query]]></category>
		<category><![CDATA[java tutorial]]></category>
		<category><![CDATA[latest java script]]></category>
		<category><![CDATA[latest java script plugins]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=61</guid>
		<description><![CDATA[It’s really amazing to see what one can create using jQuery. Developers just don’t stop making incredibly interactive web applications every now and then. This post just demonstrates excellent examples of some of the best jQuery plugins out there. jQuery Sliders 1) Slider Gallery- A similar effect used to showcase the products on the Apple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=61&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It’s really amazing to see what one can create using jQuery. Developers just don’t stop making incredibly interactive web applications every now and then. This post just demonstrates excellent examples of some of the best jQuery plugins out there.</p>
<h4 class="title">jQuery Sliders</h4>
<p>1) <a class="showcase" href="http://jqueryfordesigners.com/slider-gallery/">Slider Gallery</a>- A similar effect used to showcase the products on the Apple web site. This ‘product slider’ is similar to a straight forward gallery, except that there is a slider to navigate the items, i.e. the bit the user controls to view the items. Simple stuff.</p>
<p><a class="showcase" href="http://jqueryfordesigners.com/slider-gallery/"><img src="http://noupe.com/img/j-12.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://jqueryfordesigners.com/demo/slider-gallery.html">Here</a></li>
</ul>
<hr />2) <a class="showcase" href="http://www.filamentgroup.com/lab/developing_an_accessible_slider/">Accessible slider</a>- Illustrations and code samples showing how to make a slider UI control accessible to those who aren’t running JavaScript or CSS.</p>
<p><a class="showcase" href="http://www.filamentgroup.com/lab/developing_an_accessible_slider/"><img src="http://noupe.com/img/j-22.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://www.filamentgroup.com/examples/slider/index3.php">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Manipulating Images</h4>
<p>3) <a class="showcase" href="http://remysharp.com/2007/03/19/a-few-more-jquery-plugins-crop-labelover-and-pluck/">crop, labelOver and pluck</a>-Crop-Gives your visitors the power to crop any image on the fly using JavaScript only. Also there are 2 other plugins: LabelOver and Pluck.</p>
<p><a class="showcase" href="http://remysharp.com/wp-content/uploads/2007/03/crop_example.html"><img src="http://noupe.com/img/j-15.gif" alt="" /></a></p>
<ul>
<li>Live Demo Of Crop: <a href="http://remysharp.com/wp-content/uploads/2007/03/crop_example.html">Here</a></li>
<li>Live Demo of LabelOver: <a href="http://remysharp.com/wp-content/uploads/2007/03/label_over_example.html">Here</a></li>
</ul>
<hr />4) <a class="showcase" href="http://coderseye.com/2007/semitransparent-rollovers-made-easy-with-jquery.html">Semitransparent rollovers </a>-A simple method for enabling semi-transparent rollovers which actually work on IE 6.</p>
<p><a class="showcase" href="http://coderseye.com/files/demos/pngrollover/index.html"><img src="http://noupe.com/img/j-16.gif" alt="" /></a></p>
<ul>
<li>Live Demo Of Crop: <a href="http://coderseye.com/files/demos/pngrollover/index.html">Here</a></li>
</ul>
<hr />5) <a class="showcase" href="http://www.bennadel.com/blog/1009-jQuery-Demo-Creating-A-Sliding-Image-Puzzle-Plug-In.htm">Creating A Sliding Image Puzzle Plug-In</a>- Creates sliding-image puzzles based on containers that have images. Running the demo page we get this output in the image below:</p>
<p><a class="showcase" href="http://www.bennadel.com/blog/1009-jQuery-Demo-Creating-A-Sliding-Image-Puzzle-Plug-In.htm"><img src="http://noupe.com/img/j-19.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://www.bennadel.com/resources/demo/jquery_puzzle/">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Navigation Menus</h4>
<p>6) <a class="showcase" href="http://css-tricks.com/designing-the-digg-header-how-to-download/">Digg Header</a>- This is a replica of the Digg header. Fluid width (but only to a point!), drop down menus, attractive search, easy to change colors… There is a lot of smarts in a small place in this example!</p>
<p><a class="showcase" href="http://css-tricks.com/designing-the-digg-header-how-to-download/"><img src="http://noupe.com/img/j-7.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://css-tricks.com/examples/DiggHeader/">Here</a></li>
<li>Download Code: <a href="http://css-tricks.com/examples/DiggHeader.zip">From Here</a></li>
</ul>
<hr />7) <a class="showcase" href="http://icon.cat/wiki/IconDock_En#iconDock_jQuery_Plugin">IconDock</a>- a <a title="http://jquery.com" rel="nofollow" href="http://jquery.com/">jQuery JavaScript library</a> plugin that allows you to create a menu on your web like the Mac OS X operating system <em>dock effect</em> one.</p>
<p><a class="showcase" href="http://icon.cat/wiki/IconDock_En#iconDock_jQuery_Plugin"><img src="http://noupe.com/img/j-31.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://icon.cat/software/iconDock/0.8b/dock.html">Here</a></li>
<li>Download Code: <a href="http://css-tricks.com/examples/DiggHeader.zip">From Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Accordions</h4>
<p>8 ) <a class="showcase" href="http://dev.portalzine.de/index?/Horizontal_Accordion--print">Horizontal Accordion</a>- This plugin provides some simple options to alter the accordion look and behavior.</p>
<p><a class="showcase" href="http://dev.portalzine.de/index?/Horizontal_Accordion--print"><img src="http://noupe.com/img/j-5.jpg" alt="" /></a></p>
<hr />9) <a class="showcase" href="http://berndmatzner.de/jquery/hoveraccordion/">HoverAccordion</a>- A jQuery Plugin for no-click two-level menus.</p>
<p><a class="showcase" href="http://berndmatzner.de/jquery/hoveraccordion/"><img src="http://noupe.com/img/j-32.jpg" alt="" /></a></p>
<hr />
<h4 class="title">jQuery Image Viewer</h4>
<p>10) <a class="showcase" href="http://www.dynamicdrive.com/dynamicindex4/stepcarousel.htm"> Step Carousel Viewer</a>- Displays images or even rich HTML by side scrolling them left or right. Users can step to any specific content on demand.</p>
<p><a class="showcase" href="http://www.dynamicdrive.com/dynamicindex4/stepcarousel.htm"><img src="http://noupe.com/img/j-8.gif" alt="" /></a></p>
<hr />11) <a class="showcase" href="http://www.dynamicdrive.com/dynamicindex17/featuredcontentglider.htm">Featured Content Glider</a>- You can showcase new or featured contents on your page, by turning ordinary pieces of HTML content into an interactive, “glide in” slideshow. Supports two different display modes- “manual” and “slideshow.”</p>
<p><a class="showcase" href="http://www.dynamicdrive.com/dynamicindex17/featuredcontentglider.htm"><img src="http://noupe.com/img/j-26.jpg" alt="" /></a></p>
<hr />
<h4 class="title">jQuery Charts</h4>
<p>12) <a class="showcase" href="http://moblur.org/workshop/jflot_intro/">jQuery + jFlot </a>- Plots, Canvas and Charts.</p>
<p><a class="showcase" href="http://moblur.org/workshop/jflot_intro/"><img src="http://noupe.com/img/j-4.jpg" alt="" /></a></p>
<hr />13) <a class="showcase" href="http://www.filamentgroup.com/lab/creating_accessible_charts_using_canvas_and_jquery">Accessible charts using canvas and jQuery </a>- A proof of concept for visualizing HTML table data with the canvas element by using jQuery to provides several types of editable graphs, such as Pie, Line, Area, and Bar.</p>
<p><a class="showcase" href="http://www.filamentgroup.com/lab/creating_accessible_charts_using_canvas_and_jquery/"><img src="http://noupe.com/img/j-21.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://www.filamentgroup.com/examples/charting/">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Editors</h4>
<p>14) <a class="showcase" href="http://www.avidansoft.com/dsrte/dsrte.php">Small Rich Text Editor </a>- Small footprint, Cross-browser, Ajax Image upload, HTML Cleanup with PHP back-end rich text editor with all basic Rich Text functionality included.</p>
<p><a class="showcase" href="http://www.avidansoft.com/dsrte/dsrte.php"><img src="http://noupe.com/img/j-3.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://www.avidansoft.com/dsrte/dsrte.php">Here</a></li>
<li>Download Code: <a href="http://www.avidansoft.com/dsrte/dsrte.zip">From Here</a></li>
</ul>
<hr />15)<a class="showcase" href="http://markitup.jaysalvat.com/home/">markItUp! Universal markup editor</a>- This plugin allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own Markup system can be easily implemented. Worth Checking!</p>
<p><a href="http://markitup.jaysalvat.com/home/"><img src="http://noupe.com/img/j-27.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://markitup.jaysalvat.com/examples/">Here</a></li>
<li>Download Code: <a href="http://markitup.jaysalvat.com/downloads/">From Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Flash Plugins</h4>
<p>16) <a class="showcase" href="http://jquery.lukelutman.com/plugins/flash">jQuery Flash Plugin</a>- A jQuery plugin for embedding Flash movies.</p>
<p><a class="showcase" href="http://jquery.lukelutman.com/plugins/flash"><img src="http://noupe.com/img/j-10.gif" alt="" /></a></p>
<hr />17) <a class="showcase" href="http://www.sean-o.com/jquery/jmp3/">jMP3</a>- jMP3 is an easy way make any MP3 playable directly on most any web site (to those using Flash &amp; JS),</p>
<p>using the sleek <a href="http://jeroenwijering.com/?item=Flash_Single_MP3_Player" target="_blank">Flash Single MP3 Player</a> &amp; <a href="http://jquery.com/" target="_blank">jQuery</a>.</p>
<p><a class="showcase" href="http://www.sean-o.com/jquery/jmp3/"><img src="http://noupe.com/img/j-9.gif" alt="" /></a></p>
<hr />18) <a class="showcase" href="http://www.malsup.com/jquery/media/">jQuery Media Plugin</a>- It can be used to embed virtually any media type, including Flash, Quicktime, Windows Media Player, Real Player, MP3, Silverlight, PDF and more, into a web page.</p>
<p><a class="showcase" href="http://www.malsup.com/jquery/media/#demos"><img src="http://noupe.com/img/j-36.gif" alt="" /></a></p>
<hr />
<h4 class="title">jQuery Tabs</h4>
<p>You can use the a href=”http://docs.jquery.com/UI/Tabs”&gt;jUI/Tabsto create more dynamic tab functionality.</p>
<p>19) <a class="showcase" href="http://jqueryfordesigners.com/jquery-tabs/">jQuery Tabs</a>- Typical tabbing structure which degrade nicely without JavaScript enabled.</p>
<p><a class="showcase" href="http://jqueryfordesigners.com/jquery-tabs/"><img src="http://noupe.com/img/j-11.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://jqueryfordesigners.com/demo/tabs.html">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery LightBox</h4>
<p>20) <a class="showcase" href="http://fancy.klade.lv/">Fancy Box</a>- Kinda different image zooming script for those who want something fresh. Features: Automatically scales large images to fit in window, adds a nice drop shadow under the full-size image, image sets to group related images and navigate through them</p>
<p><a class="showcase" href="http://fancy.klade.lv/"><img src="http://noupe.com/img/j-13.jpg" alt="" /></a></p>
<hr />21) <a class="showcase" href="http://blog.raduceuca.com/">Thickbox Plus</a>- Click an Image to view a ThickBox image that is resized when your window is resized to fit the window.</p>
<p><a class="showcase" href="http://blog.raduceuca.com/"><img src="http://noupe.com/img/j-1.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://lab.christianmontoya.com/thickbox-plus/">Here</a></li>
<li>Download Code: <a href="http://lab.christianmontoya.com/thickbox-plus/thickbox-plus.zip">From Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Datagrid plugins</h4>
<p>22) <a class="showcase" href="http://webplicity.net/flexigrid/">Flexi Grid</a>- Lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml based data source using Ajax to load the content. Similar in concept with the Ext Grid only its pure jQuery love, which makes it light weight and follows the jQuery mantra of running with the least amount of configuration.</p>
<p><a class="showcase" href="http://webplicity.net/flexigrid/"><img src="http://noupe.com/img/j-2.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://webplicity.net/flexigrid/">Here</a></li>
<li>Download Code: <a href="http://webplicity.net/flexigrid/flexigrid.zip">From Here</a></li>
</ul>
<hr />23) <a class="showcase" href="http://www.trirand.com/blog/?p=13">Query Grid 3.1</a>- Datagird plugin for jQuery, where the user can manipulate the number of requested pages with adding, updating, deleting row data.</p>
<p><a class="showcase" href="http://www.trirand.com/blog/?p=13"><img src="http://noupe.com/img/j-34.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://trirand.com/jqgrid/jqgrid.html">Here</a></li>
<li>Download Code: <a href="http://www.trirand.com/jqgrid/jqGrid.zip">From Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Field Manipulation</h4>
<p>24) <a class="showcase" href="http://web2ajax.fr/2008/02/03/facebook-like-jquery-and-autosuggest-search-engine/"> FaceBook Like &#8211; jQuery and autosuggest Search Engine</a>-  This autosuggest search engine is inspired from facebook for design,</p>
<p>use <a href="http://www.jquery.info/">jQuery</a> as ajax framework and <a href="http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html">BSN Autosuggest</a> libs.</p>
<p><a class="showcase" href="http://jqueryfordesigners.com/coda-popup-bubbles"><img src="http://noupe.com/img/j-30.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://web2ajax.fr/examples/facebook_searchengine/">Here</a></li>
</ul>
<hr />25) <a class="showcase" href="http://digitalbush.com/projects/masked-input-plugin"> Masked Input Plugin</a>- It allows a user to more easily enter fixed width input where you would like them to enter the data in a certain format (dates,phone numbers, etc).</p>
<p><a class="showcase" href="http://digitalbush.com/projects/masked-input-plugin"><img src="http://noupe.com/img/j-33.jpg" alt="" /></a></p>
<hr />
<h4 class="title">jQuery with cool animation Effects</h4>
<p>26) <a class="showcase" href="http://ui.jquery.com/enchant/1.0a/demos/">jQuery Enchant</a>- Devoted to rich effects. It already features all effects you know from scriptaculous/interface, as well as many more great additions: color animations, class animations and highly configurable effects.</p>
<p><a class="showcase" href="http://ui.jquery.com/enchant/1.0a/demos/"><img src="http://noupe.com/img/j-20.jpg" alt="" /></a></p>
<hr />27) <a class="showcase" href="http://fromvega.com/wordpress/2007/07/14/easydrag-jquery-plugin/">EasyDrag jQuery Plugin</a>- Add the ability to drag and drop almost any DOM element without much effort. So it’s simple to use and you can also attach handlers both to the drag and to the drop events.</p>
<p><a class="showcase" href="http://fromvega.com/wordpress/2007/07/14/easydrag-jquery-plugin/"><img src="http://noupe.com/img/j-14.jpg" alt="" /></a></p>
<hr />28) <a class="showcase" href="http://www.learningjquery.com/2008/02/simple-effects-plugins">Simple Effects Plugins</a>- Nice animation effects that can easily toggle, hide, show, fade, slide elements.</p>
<p><a class="showcase" href="http://www.learningjquery.com/2008/02/simple-effects-plugins"><img src="http://noupe.com/img/j-18.gif" alt="" /></a></p>
<hr />29) <a class="showcase" href="http://jqueryfordesigners.com/slide-out-and-drawer-effect/">Slide out and drawer effect</a>- A demonstration of accordion effect in action, where the mouse settles on the title of the ’section’ and the associated links are exposed. What makes this effect particularly cool, is that the drawers maintain a fixed height and slide between restricted area.</p>
<p><a class="showcase" href="http://jqueryfordesigners.com/slide-out-and-drawer-effect/"><img src="http://noupe.com/img/j-6.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://jqueryfordesigners.com/demo/plugin-slide-demo.html">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Worth Checking Plugins</h4>
<p>30) <a class="showcase" href="http://www.learningjquery.com/2006/12/multiple-fancy-drop-caps">crop, labelOver and pluck</a>- How to create a drop cap and apply it to every paragraph in a DIV.</p>
<p><a class="showcase" href="http://www.learningjquery.com/2006/12/multiple-fancy-drop-caps"><img src="http://noupe.com/img/j-17.gif" alt="" /></a></p>
<hr />31) <a class="showcase" href="http://blog.jeremymartin.name/2008/02/blogger-trick-style-author-comments.html"> Style Author Comments Differently with jQuery</a>- Nice custom styling applied to comments left by the author.</p>
<p><a class="showcase" href="http://blog.jeremymartin.name/2008/02/blogger-trick-style-author-comments.html"><img src="http://noupe.com/img/j-23.gif" alt="" /></a></p>
<hr />32) <a class="showcase" href="http://swedishfika.com/2008/03/04/creating-a-fading-header/">Creating a fading header</a>- A simple example using jQuery and CSS that shows you how to create the fading header technique.</p>
<p><a class="showcase" href="http://swedishfika.com/2008/03/04/creating-a-fading-header/"><img src="http://noupe.com/img/j-24.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://bitsamppixels.com/fading-header/">Here</a></li>
</ul>
<hr />33) <a class="showcase" href="http://jqueryfordesigners.com/coda-popup-bubbles">Coda Bubble</a>-  A demonstration of the ‘puff’ popup bubble effect as seen over the download link on the <a href="http://www.panic.com/coda/">Coda web site</a></p>
<p><a class="showcase" href="http://jqueryfordesigners.com/coda-popup-bubbles"><img src="http://noupe.com/img/j-25.jpg" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://jqueryfordesigners.com/demo/coda-bubble.html">Here</a></li>
</ul>
<hr />34) <a class="showcase" href="http://davehauenstein.com/blog/archives/28">Another In-Place Editor</a>- This is a script that turns any element, or an array of elements into an AJAX in place editor using one line of code.</p>
<p><a class="showcase" href="http://davehauenstein.com/blog/archives/28"><img src="http://noupe.com/img/j-35.gif" alt="" /></a></p>
<ul>
<li>Live Demo: <a href="http://davehauenstein.com/code/inplace.php">Here</a></li>
</ul>
<hr />35) <a class="showcase" href="http://www.malsup.com/jquery/taconite/">jQuery Taconite</a>- The jQuery Taconite Plugin allows you to easily make multiple DOM updates using the results of a single AJAX call. It processes an XML command document that contain instructions for updating the DOM.</p>
<ul>
<li>Live Demo: <a href="http://www.malsup.com/jquery/taconite/#examples">Here</a></li>
</ul>
<hr />
<h4 class="title">jQuery Web Applications</h4>
<p>36) <a class="showcase" href="http://www.genfavicon.com/">GenFavicon</a>- A cool online generator that creats little favicons used throughout the web. You have the option of either specifying a URL for the image you’d like to convert or uploading it to the site for processing.</p>
<p><a class="showcase" href="http://www.genfavicon.com/"><img src="http://noupe.com/img/j-28.gif" alt="" /></a></p>
<hr />37) <a class="showcase" href="http://writemaps.com/">WriteMaps</a>- WriteMaps provides an easy-to-use interface for creating, editing, and sharing your sitemaps.</p>
<p><a class="showcase" href="http://writemaps.com/"><img src="http://noupe.com/img/j-29.jpg" alt="" /></a></p>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Latest News, Web Development Tagged: java, java plugins, java script, java script plugins, java script query, java tutorial, latest java script, latest java script plugins, plugins <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=61&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/11/37-more-shocking-jquery-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>

		<media:content url="http://noupe.com/img/j-12.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-22.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-15.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-16.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-19.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-7.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-31.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-5.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-32.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-8.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-26.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-4.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-21.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-3.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-27.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-10.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-9.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-36.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-11.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-13.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-1.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-2.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-34.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-30.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-33.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-20.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-14.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-18.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-6.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-17.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-23.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-24.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-25.jpg" medium="image" />

		<media:content url="http://noupe.com/img/j-35.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-28.gif" medium="image" />

		<media:content url="http://noupe.com/img/j-29.jpg" medium="image" />
	</item>
		<item>
		<title>45+ Fresh Out of the oven jQuery Plugins</title>
		<link>http://expertzweb.wordpress.com/2008/10/11/45-fresh-out-of-the-oven-jquery-plugins/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/11/45-fresh-out-of-the-oven-jquery-plugins/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 18:38:40 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java plugins]]></category>
		<category><![CDATA[java script]]></category>
		<category><![CDATA[java script plugins]]></category>
		<category><![CDATA[java script query]]></category>
		<category><![CDATA[java tutorial]]></category>
		<category><![CDATA[latest java script]]></category>
		<category><![CDATA[latest java script plugins]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=59</guid>
		<description><![CDATA[This month ago we’ve presented the 50 favorite jQuery plugins and 37 More Shocking jQuery Plugins for many developers use and we promised that the second version will be coming soon. Today, we are going to introduce 45+ more jquery plugins that were recently created, so you don’t have to do the search as we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=59&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="padding-top:10px;">This month ago we’ve presented the <a href="http://blog.expertzweb.com/archives/166">50 favorite jQuery plugins</a> and <a href="http://blog.expertzweb.com/?p=176">37 More Shocking jQuery Plugins </a> for many developers use and we promised that the second version will be coming soon. Today, we are going to introduce 45+ more jquery plugins that were recently created,<span> so you don’t have to do the search as we did it and will continue to do it to build a useful library of jquery plugins and solutions.</span></p>
<hr class="dotted" />
<h4 class="title">Image SlideShows and Galleries</h4>
<p>1) <a href="http://monc.se/galleria/">Galleria</a> -Is a javascript image gallery written in jQuery. It loads the images one by one from an unordered list and displays thumbnails when each image is loaded. It will create thumbnails for you if you choose so, scaled or unscaled, centered and cropped inside a fixed thumbnail box defined by CSS.</p>
<p><a href="http://monc.se/galleria/demo/demo_01.htm#"><img src="http://noupe.com/img/2j15.jpg" alt="" /></a></p>
<hr class="dotted" />2) <a href="http://www.openstudio.fr/jQuery-Multimedia-Portfolio.html?lang=en">jQuery Multimedia Portfolio</a> -Non obstrusive and accessible portfolio supporting multiple media : photos, video (flv), audio (mp3), will automatically detect the extension of each media and apply the adapted player.</p>
<p><a href="http://www.openstudio.fr/jQuery-Multimedia-Portfolio.html?lang=en"><img src="http://noupe.com/img/2j20.gif" alt="" /></a></p>
<hr class="dotted" />3) <a href="http://www.webinventif.fr/wp-content/uploads/projets/wslide/">wSlide</a> -Change your lists in animated box (with pagination)</p>
<p><a href="http://www.webinventif.fr/wp-content/uploads/projets/wslide/"><img src="http://noupe.com/img/2j25.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Tag Clouds</h4>
<p>4) <a href="http://www.noupe.com/css/jquery-hover-sub-tag-cloud.html">Hover Sub Tags</a>- Using jQuery to reduce the size of the tag cloud that you have on your sites, for example if you have Ajax as a tag, you can have jquery, mootools, etc… as sub-tags. A Sub Tag Cloud will appear when hovering over the main Tag links.</p>
<p><a href="http://noupe.com/examples/tagcloud/tag-cloud.html"><img src="http://noupe.com/img/2j36.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Pagination</h4>
<p>5) <a href="http://plugins.jquery.com/project/pagination">Pagination</a>- Create navigational elements, when you have a a large list of items you can display them grouped in pages and present navigational elements to move from one page to another.</p>
<p><a href="http://d-scribe.de/webtools/jquery-pagination/demo.htm"><img src="http://noupe.com/img/2j26.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Navigation</h4>
<p>6) <a href="http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm">Accordion Menu</a> -In this Accordion menu example, the menu headers are H3 tags, with each sub menu being UL tags that expand/ contract.</p>
<p><a href="http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm"> <img src="http://noupe.com/img/2j13.gif" alt="" /></a></p>
<hr class="dotted" />7) <a href="http://jquery.bassistance.de/treeview/demo/">jQuery Treeview Plugin </a></p>
<p><a href="http://jquery.bassistance.de/treeview/demo/"> <img src="http://noupe.com/img/2j31.gif" alt="" /></a></p>
<hr class="dotted" />8 ) <a href="http://www.ndoherty.com/demos/coda-slider/1.1.1/">Coda-Slider</a>- Amazing jQuery Coda-Slider can be used for Nice, slick content presentation.</p>
<p><a href="http://www.ndoherty.com/demos/coda-slider/1.1.1/"> <img src="http://noupe.com/img/t12.gif" alt="" /></a></p>
<hr class="dotted" />9) <a href="http://letmehaveblog.blogspot.com/2007/10/haccordion-simple-horizontal-accordion.html">Simple Horizontal Accordion</a></p>
<p><a href="http://letmehaveblog.blogspot.com/2007/10/haccordion-simple-horizontal-accordion.html"> <img src="http://noupe.com/img/2j32.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Tables and Grids</h4>
<p>10) <a href="http://pure-essence.net/2008/02/26/jquery-plugin-tablerowcheckboxtoggle/">TableRowCheckboxToggle</a> &#8211; It generically adds the toggle function to any table rows you specify based on the css class names. It will by default toggle any checkboxes within the table row.</p>
<p><a href="http://pure-essence.net/stuff/webTips/jqueryTableRowCheckboxToggle.html"> <img src="http://noupe.com/img/2j1.gif" alt="" /></a></p>
<hr class="dotted" />11) <a href="http://dev.iceburg.net/jquery/tableEditor/demo.php">TableEditor</a> &#8211; TableEditor provides flexible in place editing of HTML tables.</p>
<p><a href="http://dev.iceburg.net/jquery/tableEditor/demo.php"> <img src="http://noupe.com/img/2j30.gif" alt="" /></a></p>
<hr class="dotted" />12) <a href="http://www.reconstrukt.com/ingrid/">Ingrid</a> &#8211; ngrid is an unobtrusive jQuery component that adds datagrid behaviors (column resizing, paging, sorting, row and column styling, and more) to your tables.</p>
<p><a href="http://www.reconstrukt.com/ingrid/example1.html"> <img src="http://noupe.com/img/2j34.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Forms</h4>
<p>13) <a href="http://www.whitespace-creative.com/jquery/jNice/">jQuery Nice Form</a> &#8211; Create custom looking form elements, that function like normal form elements.</p>
<p><a href="http://www.whitespace-creative.com/jquery/jNice/"> <img src="http://noupe.com/img/2j2.gif" alt="" /></a></p>
<hr class="dotted" />14) <a href="http://jmar777.blogspot.com/2008/02/easy-multi-select-transfer-with-jquery.html">Easy Multi Select Transfer</a>- Allowing options to be traded from one multi select to another.</p>
<p><a href="http://jmar777.blogspot.com/2008/02/easy-multi-select-transfer-with-jquery.html"> <img src="http://noupe.com/img/2j42.gif" alt="" /></a></p>
<hr class="dotted" />15) <a href="http://malsup.com/jquery/form/">jQuery Form Plugin</a>- Allows you to easily and unobtrusively upgrade HTML forms to use AJAX by using ajaxForm and ajaxSubmit methods to gather information from the form element and determine how to manage the submit process which allows you to have full control over how the data is submitted.</p>
<hr class="dotted" />
<h4 class="title">Scrolling</h4>
<p>16) <a href="http://flesler.blogspot.com/2008/02/jqueryserialscroll.html">jQuery.SerialScroll</a> &#8211; This plugin allows you to easily animate any series of elements, by sequentially scrolling them. You can use it as a section slider, text scroller, slideshows, and news ticker.</p>
<p><a href="http://flesler.webs.com/jQuery.SerialScroll/"> <img src="http://noupe.com/img/2j10.gif" alt="" /></a></p>
<hr class="dotted" />17) <a href="http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html">liScroll </a> &#8211; LiScroll is a jQuery plugin that transforms any given unordered list into a scrolling News Ticker</p>
<hr class="dotted" />18) <a href="http://n.efario.us/category/jquery/spinner/">Spinner</a> &#8211; Allows you to cycle through millions of items or groups of items with the appearance of a scroller and functionality of a page horizontally or vertically.</p>
<p><a href="http://n.efario.us/jquery/spinner/"> <img src="http://noupe.com/img/2j41.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Form Elements</h4>
<p>19) <a href="http://projects.bundleweb.com.ar/jWYSIWYG/">jWYSIWYG</a> &#8211; This plugin is an inline content editor to allow editing rich HTML content on the fly.</p>
<p><a href="http://projects.bundleweb.com.ar/jWYSIWYG/"> <img src="http://noupe.com/img/2j5.gif" alt="" /></a></p>
<hr class="dotted" />20) <a href="http://www.codeassembly.com/Simple-chained-combobox-plugin-for-jQuery/">Simple chained combobox</a> -Very simple chained selects plugin for jQuery with JSON processing and callback feature, chain multiple selects with ease.</p>
<p><a href="http://www.codeassembly.com/examples/jquerycombo/test.html"> <img src="http://noupe.com/img/2j14.gif" alt="" /></a></p>
<hr class="dotted" />21) <a href="http://widowmaker.kiev.ua/checkbox/">jQuery checkbox</a></p>
<p><a href="http://widowmaker.kiev.ua/checkbox/"> <img src="http://noupe.com/img/2j18.gif" alt="" /></a></p>
<hr class="dotted" />22) <a href="http://lab.berkerpeksag.com/jGrow">jGrow</a> -jGrow is a jQuery plug-in that makes the textarea adjust its size according to the length of the text.</p>
<p><a href="http://lab.berkerpeksag.com/jGrow#samples"> <img src="http://noupe.com/img/2j16.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Toggling</h4>
<p>23) <a href="http://jmar777.blogspot.com/2008/02/jtruncate-in-action.html">jTruncate in Action</a> &#8211; jTruncate provides simple yet customizable truncation for text entities in your web page.</p>
<p><a href="http://jmar777.blogspot.com/2008/02/jtruncate-in-action.html"> <img src="http://noupe.com/img/2j7.gif" alt="" /></a></p>
<hr class="dotted" />24) <a href="http://jquery.andreaseberhard.de/toggleElements/">toggleElements</a> &#8211; toggleElements is designed to hide informations on your site and show it only when the user requests more information.</p>
<p><a href="http://jquery.andreaseberhard.de/toggleElements/"> <img src="http://noupe.com/img/2j37.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Gradients and Shadows</h4>
<p>25) <a href="http://eyebulb.com/dropshadow/">Drop Shadows</a> &#8211; Interesting Drop shadow effect generated by a jQuery Plugin.</p>
<p><a href="http://eyebulb.com/dropshadow/"> <img src="http://noupe.com/img/2j9.gif" alt="" /></a></p>
<hr class="dotted" />26) <a href="http://www.unitorganizer.com/myblog/2007/08/gradient_jquery_plugin.html">Gradient jQuery plugin</a> &#8211; It allows you to define a gradient fill and have an element filled with a gradient. You can set the direction of the gradient (right-left or up-down) and the opacity of the gradient easily.</p>
<p><a href="http://www.unitorganizer.com/javascript/gradients/"> <img src="http://noupe.com/img/2j11.gif" alt="" /></a></p>
<hr class="dotted" />27) <a href="http://blog.brandonaaron.net/my-jquery-plugins/gradient/">Gradient</a> &#8211; The gradient plugin adds a dynamically created configurable gradient to the background of an element without the use of images.</p>
<p><a href="http://brandonaaron.net/jquery/plugins/gradient/test/"> <img src="http://noupe.com/img/2j29.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Lightbox</h4>
<p>28) <a href="http://famspam.com/facebox">Facebox</a> -Is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote pages.</p>
<p><a href="http://famspam.com/facebox"><img src="http://noupe.com/img/2j17.gif" alt="" /></a></p>
<hr class="dotted" />29) <a href="http://www.balupton.com/sandbox/jquery_lightbox/">jQuery Lightbox Plugin</a>- (balupton edition)</p>
<p><a href="http://www.balupton.com/sandbox/jquery_lightbox/"><img src="http://noupe.com/img/2j44.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">Color Picker</h4>
<p>30) <a href="http://vreboton.ibacolod.com/DotNetNuke/ControlsandTips/jQueryColorPicker/tabid/69/Default.aspx">jQueryColorPicker</a> &#8211; A simple jquery color picker plugin that can make user change the color of the background of the page easily.</p>
<p><a href="http://vreboton.ibacolod.com/DotNetNuke/ControlsandTips/jQueryColorPicker/tabid/69/Default.aspx"><img src="http://noupe.com/img/2j19.gif" alt="" /></a></p>
<hr class="dotted" />
<h4 class="title">This is worth checking out</h4>
<p>31) <a href="http://www.openstudio.fr/Animated-InnerFade-with-JQuery.html">Animated InnerFade</a>- Full w3c compliant animated slideshow with sliding effect on large images.</p>
<p><a href="http://www.openstudio.fr/Animated-InnerFade-with-JQuery.html"><img src="http://noupe.com/img/2j24.gif" alt="" /></a></p>
<hr class="dotted" />32) <a href="http://www.ezjquery.com/pop.html">Easy POP Show 1.0 Release</a> &#8211; Full screen show for slide news or Image Gallery.</p>
<p><a href="http://www.ezjquery.com/pop.html"> <img src="http://noupe.com/img/2j8.gif" alt="" /></a></p>
<hr class="dotted" />33) <a href="http://jsgt.org/lib/jquery/plugin/jqchart/nightly/nightly.htm">jqChart</a>- Ajax &amp; Draggable Simple Chart on Canvas+jQuery.</p>
<p><a href="http://jsgt.org/lib/jquery/plugin/jqchart/nightly/nightly.htm"><img src="http://noupe.com/img/2j23.gif" alt="" /></a></p>
<hr class="dotted" />34) <a href="http://marcgrabanski.com/code/ui-datepicker/">UI Datepicker</a> -A simple jQuery UI Datepicker. Just add a text input field to your page and then attach the datepicker to it.</p>
<p><a href="http://marcgrabanski.com/code/ui-datepicker/"> <img src="http://noupe.com/img/2j35.gif" alt="" /></a></p>
<hr class="dotted" />35) <a href="http://plugins.jquery.com/project/JSmile">JSmile</a> &#8211; A totally unobtrusive way for both (x)html and javascript events/functionality, this plug-in allows you to add, and remove, smiles in an entire document or only in some specified element.</p>
<p><a href="http://packed.it/JSmile/demo/"> <img src="http://noupe.com/img/2j3.gif" alt="" /></a></p>
<hr class="dotted" />36) <a href="http://odyniec.net/projects/imgareaselect/">ImgAreaSelect</a> &#8211; imgAreaSelect is a jQuery  plugin for selecting a rectangular area of an image.</p>
<p><a href="http://odyniec.net/projects/imgareaselect/"> <img src="http://noupe.com/img/2j4.gif" alt="" /></a></p>
<hr class="dotted" />37) <a href="http://www.designerkamal.com/jPrintArea/">jPrintArea</a>-jPrintArea is a small jquery plugin to print only contents of a specified element.</p>
<p><a href="http://www.designerkamal.com/jPrintArea/">Check out their demo page</a></p>
<hr class="dotted" />38) <a href="http://boedesign.com/lab/jtabber-for-jquery/">jTabber</a>- Allows you to scroll through content by clicking on tabs, without the page having to reload.</p>
<p><a href="http://boedesign.com/lab/jtabber-for-jquery/"><img src="http://noupe.com/img/2j27.gif" alt="" /></a></p>
<hr class="dotted" />39) <a href="http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm"> jQuery Calculation Plug-in</a> &#8211; The Calculation plug-in is designed to give easy-to-use jQuery functions for commonly used mathematical functions.</p>
<p><a href="http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm"> <img src="http://noupe.com/img/2j6.gif" alt="" /></a></p>
<hr class="dotted" />40) <a href="http://www.ollicle.com/eg/jquery/biggerlink/">jquery.biggerlink</a> &#8211; A jQuery plugin to make it really easy to enable the specified element/s to behave as a proxy for their first contained link.</p>
<p><a href="http://www.ollicle.com/eg/jquery/biggerlink/"> <img src="http://noupe.com/img/2j40.gif" alt="" /></a></p>
<hr class="dotted" />41) <a href="http://binarybonsai.com/archives/2007/10/15/humanized-messages-for-jquery/">Humanized Messages</a>- It’s simply a large and translucent message that’s displayed over the contents of your screen. They fade away when the user takes any action (like typing or moving the mouse).</p>
<p><a href="http://binarybonsai.com/misc/humanmsg/"><img src="http://noupe.com/img/2j33.gif" alt="" /></a></p>
<hr class="dotted" />42) <a href="http://www.protofunc.com/scripts/jquery/ajaxManager/">Ajax Manager</a> -Helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order responses).</p>
<p><a href="http://www.protofunc.com/scripts/jquery/ajaxManager/"> <img src="http://noupe.com/img/2j12.gif" alt="" /></a></p>
<hr class="dotted" />43) <a href="http://www.protofunc.com/scripts/jquery/backgroundPosition/">Background-Position Animation</a></p>
<p><a href="http://www.protofunc.com/scripts/jquery/backgroundPosition/"> <img src="http://noupe.com/img/2j22.gif" alt="" /></a></p>
<hr class="dotted" />44) <a href="http://www.appelsiini.net/projects/lazyload">Lazyload</a>-Delays loading of images in (long) web pages. Images below the fold (the ones lower than window bottom) are not loaded. When scrolling down they are loaded when needed.</p>
<p><a href="http://www.appelsiini.net/projects/lazyload">Check out their demo page</a></p>
<hr class="dotted" />45) <a href="http://remysharp.com/2008/02/28/upgraded-jquery-tag-suggestions/">jQuery Tag Suggestion</a>- The same tag suggesting as-you-type support that del.icio.us is uses.</p>
<p><a href="http://remysharp.com/2008/02/28/upgraded-jquery-tag-suggestions/">Check out their demo page</a></p>
<hr /><img src="http://noupe.com/img/2j43.gif" alt="" /></p>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Latest News, Web Development Tagged: java, java plugins, java script, java script plugins, java script query, java tutorial, latest java script, latest java script plugins, plugins <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=59&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/11/45-fresh-out-of-the-oven-jquery-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>

		<media:content url="http://noupe.com/img/2j15.jpg" medium="image" />

		<media:content url="http://noupe.com/img/2j20.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j25.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j36.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j26.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j13.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j31.gif" medium="image" />

		<media:content url="http://noupe.com/img/t12.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j32.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j1.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j30.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j34.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j2.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j42.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j10.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j41.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j5.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j14.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j18.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j16.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j7.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j37.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j9.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j11.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j29.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j17.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j44.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j19.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j24.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j8.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j23.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j35.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j3.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j4.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j27.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j6.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j40.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j33.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j12.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j22.gif" medium="image" />

		<media:content url="http://noupe.com/img/2j43.gif" medium="image" />
	</item>
		<item>
		<title>Using htaccess Redirect Rule</title>
		<link>http://expertzweb.wordpress.com/2008/10/11/using-htaccess-redirect-rule/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/11/using-htaccess-redirect-rule/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 18:29:38 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[htaccess Redirect Rule]]></category>
		<category><![CDATA[Redirect Rule]]></category>
		<category><![CDATA[Redirect Rule of htaccess]]></category>
		<category><![CDATA[using htaccess]]></category>
		<category><![CDATA[Using htaccess Redirect Rule]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=57</guid>
		<description><![CDATA[I will tell you right off the bat that I don’t “get” regular expressions, and I don’t get .htacess rewrite rules. I wish I understood them better, but there’s some part of my brain that just fights me every time I try to get a better all-around understanding. Still, I have to (and want to) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=57&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="entry">
<p>I will tell you right off the bat that I don’t “get” regular expressions, and I don’t get .htacess rewrite rules. I wish I understood them better, but there’s some part of my brain that just fights me every time I try to get a better all-around understanding. Still, I have to (and want to) do stuff with htaccess, so I end up digging for code online, and trying stuff until something works. I wish I knew more about WHY it worked, but I’m just happy that it works at all. <img class="wp-smiley" src="http://www.scriptygoddess.com/wp-includes/images/smilies/icon_smile.gif" alt=")" /></p>
<p>Now that I’m done with my disclaimer, on to the point of this post. I had to use a htaccess file to redirect a subdomain to a directory in the main domain. For example: http://blog.mysite.com needed to point to http://www.mysite.com/blog/</p>
<p>After much digging and trial and error, this seems to work:</p>
<p><code>RewriteEngine On<br />
RewriteCond %{HTTP_HOST} ^blog\.mysite\.com<br />
RewriteRule ^(.*)$ /blog/$1 [L]</code></div>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Latest News, Web Development Tagged: htaccess, htaccess Redirect Rule, Redirect Rule, Redirect Rule of htaccess, using htaccess, Using htaccess Redirect Rule <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=57&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/11/using-htaccess-redirect-rule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>

		<media:content url="http://www.scriptygoddess.com/wp-includes/images/smilies/icon_smile.gif" medium="image">
			<media:title type="html">)</media:title>
		</media:content>
	</item>
		<item>
		<title>Building Dynamic Menus In wordpress</title>
		<link>http://expertzweb.wordpress.com/2008/10/09/building-dynamic-menus-in-wordpress/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/09/building-dynamic-menus-in-wordpress/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 12:03:16 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dynamic menu]]></category>
		<category><![CDATA[dynamic menu in wordpress]]></category>
		<category><![CDATA[dynamic wordpress menu]]></category>
		<category><![CDATA[menu in wordperss]]></category>
		<category><![CDATA[menu tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress menu]]></category>
		<category><![CDATA[wordpress tutorial]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=55</guid>
		<description><![CDATA[More and more people are using WordPress as a Content Management System (CMS), and for good reason. It’s well supported, produces good mark-up, and it’s flexible. But when using it as a CMS it suddenly becomes very important to optimize the support of WordPress “Pages.” Unlike post, archive, and category links, a web site’s “Pages” [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=55&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="entrytext">
<p>More and more people are using <a href="http://wordpress.org/">WordPress</a> as a Content Management System (<abbr>CMS</abbr>), and for good reason. It’s well supported, produces good mark-up, and it’s flexible. But when using it as a <abbr>CMS</abbr> it suddenly becomes very important to optimize the support of WordPress “Pages.” Unlike post, archive, and category links, a <em>web site’s</em> “Pages” have the utmost importance. This article will teach you how to produce a dynamic WordPress “Pages” navigation menu that looks good and behaves as a main navigation menu should.</p>
<h3>To Begin With…</h3>
<p>The first thing to consider is placement. For a vertical menu  I would suggest placing the code I will supply in the <em>sidebar.php</em> file under the “sidebar” <code>div</code> if you have one. And if you’re going for a horizontally-displayed navigation menu I suggest adding the code in the <em>header.php</em> file underneath your main heading.</p>
<h3>The Markup</h3>
<p>Here’s the mark-up you will want to place in your file of choice.</p>
<pre>&lt;ul id="nav"&gt;

 &lt;li class="current_page_item"&gt;&lt;a title="You are Home" href="&lt;?php echo get_settings('home'); ?&gt;"&gt;Blog Navigation&lt;/a&gt;&lt;/li&gt;

 &lt;li&gt;&lt;a title="Click for Home" href="&lt;?php echo get_settings('home'); ?&gt;"&gt;Blog Home&lt;/a&gt;&lt;/li&gt;

 &lt;small id="code4"&gt;&lt;!--&lt;a href="#note4" mce_href="#note4"&gt;See Note 4--&gt;&lt;/small&gt;

 &lt;li&gt;&lt;a class="rss" title="Really Simply Syndication" rel="alternate" href="&lt;?php bloginfo('rss2_url'); ?&gt;"&gt;RSS Feed&lt;/a&gt;&lt;/li&gt;

 &lt;/ul&gt;</pre>
<h4>Markup Notes</h4>
<p>Now to explain what’s what in the script above.</p>
<dl>
<dt>Note 1</dt>
<dd>I first identify the menu with a “nav” ID. This isn’t needed for styling since WordPress generates the list-item classes in its core, but I’m using it anyway as it serves two purposes. The “page_item” class doesn’t really need to be there. Go with it; editing core files isn’t advisable as it’ll impede upgrading WordPress. The main reason I offer this is to use <code>#nav</code> as a fragment identifier so as to use it as a bookmark link target for a “Jump to Navigation” link: <code><a href="#nav">Jump to Navigation</a></code> (<a href="#code1">Code 1</a>)</dd>
<dt>Note 2</dt>
<dd>This is a bit of page negotiation since I want the menu to have a home page link — something not provided on the page list by default. When you’re on the index this will say “Blog Navigation” and be styled as a current page link, but if you’re on any other page, including a “paged” home (when you view older posts via a page turner link), the link will say “Blog Home” instead and will look clickable instead of like the “current page” style. (<a href="#code2">Code 2</a>)</dd>
<dt>Note 3</dt>
<dd>This is the meat and potatoes so to speak. This is the code for the dynamic menu produced by the WordPress core. This will produce page links in list item tags: <code> </code></p>
<li>. Each will bear the “page_item” class except the current page where it’ll also bear the “current_page_item” class. I use only the latter. This conditional tag has two parameters in the function:
<ol>
<li><code>sort_column=menu_order</code> — This allows you to use the page ordering feature built into WordPress. This ensures you can put your page links in an order you deem logical.</li>
<li><code>title_li=</code> — This parameter can contain data such as <code><br />
</code></p>
<h2>Heading</h2>
<p>. If it is removed, the word “Pages” will display between the dynamic links and the home page link. If the</p>
<h2>heading elements are left blank the word “Pages” will display in the same spot. This would be okay if there was no home page link but that’s not the case, so I give the whole parameter a null value. I could give it a “0” (zero) I suppose. (<a href="#code3">Code 3</a>)</h2>
</li>
</ol>
<p><code> </code></p>
<p><code><br />
</code></li>
</dd>
<dt>Note 4</dt>
<dd>This last link is optional. Use it if your want a prominent link to your Really Simple Syndication or RSS feed. I give this link a special “rss” class so I can give it a unique background image in the style sheet. I add it to the “<code>ul#nav</code>” selector in the style sheet so the same attributes and properties are applied. I then give it a background image in a new <abbr>CSS</abbr> block — I’ll show you what I mean next. (<a href="#code4">Code 4</a>)</dd>
</dl>
<h3>Styling the List</h3>
<p>What follows are some styles for your Cascading Style Sheet (<abbr>CSS</abbr>). These styles will produce block-level links in the vertical format. You can modify these styles to get your desired look, add backgrounds, change colors, anything you wish. To make it a horizontal menu you’ll want to float it left (right reverses the order so you’ll have to modify the scripting and markup) and list items will need the display property, “inline.” You can also give the unordered list a width and center it with margin-auto. You will also want to center-align the text, probably…</p>
<p>Nonetheless, this will offer you a simple copy and paste beginning. (All of this should be put in a container div of 200 pixels with 10 pixels of padding unless you decide to modify dimension and/or units, or you’re doing the horizontal thing.)</p>
<pre> /* This styles the unordered list element to remove bullets and align the text */
ul#nav {
list-style-type : none;
text-align : right;
}

/*
This styles the links. It’s a block-level link and the text is positioned
with padding. Other styles are defined: width, colors, text attributes, etc.
*/
ul#nav a, ul#nav a.rss {
background-color : #d3d3a7;
padding : 15px 5px 2px 10px;
margin-bottom : 10px;
width : 180px;
height : auto;
color : #333;
font-weight : bold;
font-style : normal;
display : block;
text-decoration : none;
}

/* This gives the “rss” class link a background image */
ul#nav a.rss {
background : #d3d3a7 url(images/rss.jpg) no-repeat 2px 2px;
}

/* This is only necessary for IE6 else the link margins will collapse on hover */
ul#nav li {
margin-bottom : 10px;
}

/* This removes the default left margin (indentation) */
ul#nav li {
margin-left : 0;
}

/*
Now to offer some hover and focus styles. <a title="Focus on Focus article" href="http://green-beast.com/blog/?p=93">Further specification of focus/active styles</a>
could be added but I didn’t do it in this example. I didn’t feel it was needed
*/
ul#nav a:hover, ul#nav a:focus, ul#nav a:active {
background-color : #669900;
color : #fff;
}

/* This offers up a hover/focus state image for the “rss” class link */
ul#nav a.rss:hover, ul#nav a.rss:focus {
background : #669900 url(images/rss_on.jpg) no-repeat 2px 2px;
}

/*
This style the single state of the “current_page_item” class link. Not needed for
the “rss” class link since that target page won’t display the menu
*/
ul#nav li.current_page_item a, ul#nav li.current_page_item a:hover,
ul#nav li.current_page_item a:focus, ul#nav li.current_page_item a:active {
background-color : #9e9e55;
color : #fff;
cursor : default;
text-align : left;
}</pre>
<h3>Miscellaneous</h3>
<p>Here’s some general info.</p>
<ul>
<li>You could add to the style info above to support child pages, or sub-pages, but the <abbr>CSS</abbr> I provided doesn’t support that link type in a special way — the subpage links <em>and</em> the current page link will both be marked the same way.</li>
<li>You could also modify the script part of this menu if you had a static home page. Please note, however, that I’m not <em>sure</em> if a modification is needed to tell the truth. I haven’t tried it in such an application. You tell me.</li>
<li>What I have on this site is custom made because I currently have several non-WordPress pages. Thus, if you want to see an example of this menu, please check out the sidebar on my <a href="http://green-beast.com/beastblog/">BeastBlog v.2.0 theme support blog</a>, but please know that it is slightly different than what I’m offering here. I added a “btn” class in addition to the “nav” ID. Doing it this way allows advanced theme users — since the theme is publically available — the ability to easily give additional menus the same styling via the “btn” class (because IDs must be unique on any given page while classes can be used repeatedly).</li>
<li>In my example, when on the home page, I offer a link. This doesn’t have to be the case. A heading in a list item could be styled, plain text could be offered, what ever you want. I chose to do this instead. Laziness.</li>
</ul>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></div>
<br />Posted in Latest News, Web Development Tagged: dynamic menu, dynamic menu in wordpress, dynamic wordpress menu, menu in wordperss, menu tutorial, wordpress, wordpress menu, wordpress tutorial <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=55&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/09/building-dynamic-menus-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
		<item>
		<title>Get Started with PHP in FileMaker Pro</title>
		<link>http://expertzweb.wordpress.com/2008/10/09/get-started-with-php-in-filemaker-pro/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/09/get-started-with-php-in-filemaker-pro/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 11:57:32 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Desigining]]></category>
		<category><![CDATA[filemaker]]></category>
		<category><![CDATA[filemaker tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Filemaker API Tutorial]]></category>
		<category><![CDATA[PHP filemaker Integration]]></category>
		<category><![CDATA[PHP tutorial]]></category>
		<category><![CDATA[php tutorial filemaker web development]]></category>
		<category><![CDATA[start php filemaker]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=53</guid>
		<description><![CDATA[WEB DEVELOPMENT Get Started with PHP in FileMaker Pro Leverage the power of PHP, a server-side scripting language, to speed and secure Web queries. By Bob Bowers, Contributing Editor PHP is a popular, powerful, and free middleware tool for building Web applications. It&#8217;s a server-side embedded scripting language, much like other middleware tools such as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=53&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table border="0">
<tbody>
<tr>
<td width="670" valign="top"><!--Sub2A--><br />
<!-- m-art-head --></p>
<div class="article"><!--SECTION--></p>
<h4>WEB DEVELOPMENT</h4>
<p><!--HEADLINE--></p>
<h1>Get Started with PHP in FileMaker Pro</h1>
<p><!--GRAPHICURL--> <!--DECKHEAD --></p>
<h2>Leverage the power of PHP, a server-side scripting language, to speed and secure Web queries.</h2>
<p><!--DOWNLOAD --></p>
<div id="artdl"><!--BYLINE --></p>
<h5>By Bob Bowers, Contributing Editor</h5>
<p><!--CITY/ST--></p>
<p align="left"><!--PARTS-LINKS--></p>
</div>
<p><!-- m-art-head --><br />
<!--Sub2B--><br />
<!-- m-art-body --></p>
<div class="article"><!--FREELOOK--></p>
<div class="artpagelinks">
<div id="artbodymain">
<p><span style="font-size:x-small;">PHP is a popular, powerful, and free middleware tool for building Web applications. It&#8217;s a server-side embedded scripting language, much like other middleware tools such as Cold Fusion, ASP, JSP, and Lasso. You can configure PHP for use with a variety of Web servers on a variety of platforms, including Linux, Windows, and Mac OS X.</span></p>
<p><span style="font-size:x-small;">And you can use it to publish FileMaker Pro data to the Web. </span></p>
<p><span style="font-size:x-small;">You&#8217;ve likely heard or read something about the XML capabilities of FileMaker Pro 6. In addition to XML import and export, the Web Companion can output XML in response to an appropriately structured query. It&#8217;s this ability that lets PHP communicate with FileMaker Pro. </span></p>
<p><span style="font-size:x-small;">It&#8217;s beyond the scope of this article to teach you how to be a PHP developer. My goal is to teach you enough to whet your appetite and hopefully inspire you to give PHP a try on your next Web project. At the end of the article, I&#8217;ll list some resources you can consult for help with configuring and using PHP. Dozens of books on PHP are available as well. </span></p>
<p><strong>How it works</strong></p>
<p><span style="font-size:x-small;">PHP has built-in functions for sending requests to Web servers and processing the results. Using those functions, PHP can send a query to the Web Companion and get results back in XML. Now, if you had to assemble these queries and parse the incoming XML manually, you&#8217;d likely give up on PHP pretty quickly. Thankfully, there&#8217;s an easier way. Chris Hansen, a FileMaker developer, has written a class for PHP that does all the hard work for you. The class, which he calls &#8220;FX,&#8221; is free from his Web site, </span><span style="font-size:x-small;"><a href="http://www.iviking.org">http://www.iviking.org</a></span><span style="font-size:x-small;">. Using FX means you don&#8217;t have to know a lick of XML to get PHP to interact with FileMaker Pro. You just have to know how to use the functions Chris provides in the class, and that&#8217;s fairly easy. The documentation provided with the download is thorough and easy to follow.</span></p>
<p><strong>Try it out</strong></p>
<p><span style="font-size:x-small;">Often, the best way to understand something new is to play through a simple scenario. After you have a working model, it&#8217;s easier to go back and learn variations and exceptions. Let&#8217;s look, then, at a simple, typical Web publishing scenario using PHP. Imagine you have a FileMaker Pro database (Employee.fp5) containing employee names and phone numbers. Your goal is to make search and results pages so users can access the database via a browser over the company intranet.</span></p>
<p><span style="font-size:x-small;">A typical hardware configuration for FileMaker/PHP solutions is to have two machines:  a Web server running Apache or IIS, with PHP installed, and a separate machine running FileMaker Unlimited.  Your databases must be open on that second machine (locally or as the guest of FileMaker Server) and shared to the Web Companion. To have FileMaker Unlimited respond to requests for XML, the only configuration required is to have the Web Companion enabled.  In the Web Companion configuration screen, however, it&#8217;s a good idea to restrict access to only the IP address of the Web server. Limiting the traffic to that single IP address secures your data-bases from being accessed directly from a Web browser by hackers.</span></p>
<p><span style="font-size:x-small;">To test that you have the Web Com-panion configured properly and it will respond to requests for XML, open a browser (on any machine on the network) and type the following URL:</span></p>
<p><span style="font-size:x-small;">http:// /FMPro?-format=-fmp_xml&amp;-dbnames</span></p>
<p><span style="font-size:x-small;">In this request, you&#8217;re simply asking the Web Companion at that IP address for a list of accessible databases, formatted as XML. If you&#8217;re using a recent copy of Microsoft Internet Explorer, you should see the XML result in your browser. With other browsers, you might have to View Source to see the response.</span></p>
<table border="0" width="350" align="right">
<tbody>
<tr valign="top">
<td width="717" align="center"><img src="/articles.nsf/1a2e28757f3e796d882569010066da17/ecda9f8222e5462988256d4e00619962/$FILE/STG59377/STG59377.gif!OpenElement" alt="" width="350" height="272" /></td>
</tr>
<tr valign="top">
<td width="717"><strong><em><span style="font-size:x-small;">Figure 1:</span></em></strong><strong><span style="font-size:x-small;"> </span></strong><strong><span style="font-size:x-small;color:#ff0000;">Web interaction topology</span></strong><strong><span style="font-size:x-small;"> &#8212; In a typical FileMaker/PHP solution, Web users submit requests to a Web Server, which in turn requests information via XML from a FileMaker Unlimited machine.</span></strong></td>
</tr>
</tbody>
</table>
<p><span style="font-size:x-small;">All of the HTML pages (both static and those with embedded PHP code) reside on the Web server. Users interact with this machine rather than directly with your FileMaker Unlimited machine. Figure 1 illustrates this topology.</span></p>
<p><span style="font-size:x-small;">Any requests the Web server receives for pages with a .php extension are handed off to PHP for processing. If necessary, PHP talks to the Web Companion on your FileMaker Unlimited machine to send or retrieve data. PHP then passes back plain HTML to the Web server, which is, in turn, sent to the user&#8217;s browser. Users never see the PHP code embedded in your HTML pages. They&#8217;ll only see the post-processing results, which is simply HTML. So, take the following page for example, which I&#8217;ll call test.php:</span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> $a = 5;</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> $b = 8;</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> $c = $a * $b;</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> echo "If you multiply $a and $b, you'll get $c";</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> ?&gt;</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;">When a browser requests test.php, the Web server notices the .php extension, and hands the document off to PHP for processing. PHP executes the program code contained between the  symbols. Here, you&#8217;re asking PHP to multiply 5 and 8, then write a line of output. After execution, PHP hands back the processed document to the Web server. Thus, what the Web server sends back to the browser is simply:</span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> If you multiply 5 and 8, you'll get 40</span></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;">Now that you&#8217;ve tested both the Web Companion and the Web server independently, it&#8217;s time to write your search and results pages. As with other embedded languages (e.g., CDML, Lasso, Cold Fusion, ASP, JSP), you don&#8217;t have to have any special tools to embed PHP code in an HTML document. Just about any Web-authoring tool or text editor does the trick.</span></p>
<p><span style="font-size:x-small;">The page where users enter their search criteria is just a plain old HTML form. To display that form to the user, there&#8217;s no need to have PHP talk to the database. It&#8217;s only when the form is submitted that PHP has to perform a find in the database. So, keeping formatting to a minimum for now, your search.html page consists of the following:</span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;">XYZ Corp Employee Directory</span></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong><span style="font-size:x-small;"><br />
</span></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> Last Name:<br />
</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> name="LastName"&gt;</span></strong></tt></p>
<p></span></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong><span style="font-size:x-small;"> First Name:<br />
</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> name="FirstName"&gt;</span></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong><span style="font-size:x-small;"><br />
</span></strong></tt></p>
<p><tt><strong> </strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<table border="0" width="350" align="right">
<tbody>
<tr valign="top">
<td width="717" align="center"><img src="/articles.nsf/1a2e28757f3e796d882569010066da17/ecda9f8222e5462988256d4e00619962/$FILE/STG15128/STG15128.gif!OpenElement" alt="" width="350" height="256" /></td>
</tr>
<tr valign="top">
<td width="717"><strong><em><span style="font-size:x-small;">Figure 2:</span></em></strong><strong><span style="font-size:x-small;"> </span></strong><strong><span style="font-size:x-small;color:#ff0000;">Search page</span></strong><strong><span style="font-size:x-small;"> &#8212; The search page itself is just a plain HTML form, but it contains instructions to send the user&#8217;s entries to a PHP page for processing when the form is submitted.</span></strong></td>
</tr>
</tbody>
</table>
<p><span style="font-size:x-small;"><span style="font-size:x-small;">Take a look at the form tag on line 7. A form&#8217;s &#8220;action&#8221; attribute tells the Web server what to do with the form after it has been submitted. In this case, it instructs the Web server to send all the form data to something called findEmp.php, the next page you&#8217;re going to write. Figure 2 shows the search page as it would appear to users.</span></span></p>
<p><span style="font-size:x-small;">Now you write the code for the search results page, which I&#8217;ll call findEmp.php. Remember, the .php extension tells the Web server this page contains embedded PHP code. </span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong></strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">include ("FX.php");</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">$query = new FX("127.0.0.1", "591"); // IP address and </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> // port of the Web </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> // Companion</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">$query-&gt;SetDBData ("Employee.fp5");</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">$query-&gt;AddDBParam ('Last Name', $_POST['LastName']);</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">$query-&gt;AddDBParam ('First Name', $_POST['FirstName']);</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">$result = $query-&gt;FMFind();</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">if ($result['foundCount'] == 0) { </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> echo "No records matched your selection. Please try </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> again";</span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;">}  else { </span></strong></tt></p>
<p><tt><strong><span style="font-size:x-small;"> echo "Search Results</span></strong></tt></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;">";</span></strong></tt></span></span></p>
<p><tt><strong><span style="font-size:x-small;"> echo "</span></strong></tt></p>
<table border="1"><tt><strong>";</strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo "<br />
</span></strong></tt></strong></tt></p>
<tbody>
<tr>
<td>Last Name</td>
<td>First</p>
<p><tt><strong><span style="font-size:x-small;"> Name</span></strong></tt></td>
<td>Phone Number</td>
</tr>
<p><tt><strong><strong><span style="font-size:x-small;">";</span></strong></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> foreach ($result['data'] as $recordKey =&gt;$recordData) { </span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo "<br />
</span></strong></tt></strong></tt></p>
<tr><tt><strong><tt><strong><span style="font-size:x-small;">";</span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo " </span></strong></tt></strong></tt></p>
<td>&#8220;.$recordData['Last Name'][0].&#8221;</td>
<p><tt><strong><strong><span style="font-size:x-small;">";</span></strong></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo " </span></strong></tt></strong></tt></p>
<td>&#8220;.$recordData['First Name'][0].&#8221;</td>
<p><tt><strong><tt><strong><span style="font-size:x-small;">";</span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo " </span></strong></tt></strong></tt></p>
<td>&#8220;.$recordData['Phone Number'][0].&#8221;</td>
<p><tt><strong><tt><strong><span style="font-size:x-small;">";</span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo "</span></strong></tt></strong></tt></tr>
<p><tt><strong><tt><strong><span style="font-size:x-small;">";</span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> } </span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> echo "</span></strong></tt></strong></tt></tbody>
</table>
<p><tt><strong></strong></tt></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;">";</span></strong></tt></span></strong></tt></span></span></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;">} </span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;">?&gt;</span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong></strong></tt></strong></tt></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><tt><strong></strong></tt></span></strong></tt></span></span></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"><a href="#">Search Again</a></span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong></strong></tt></strong></tt></p>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><tt><strong></strong></tt></span></strong></tt></span></span></p>
<p><tt><strong><tt><strong><span style="font-size:x-small;"> </span></strong></tt></strong></tt></p>
<p><tt><strong><tt><strong></strong></tt></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong>The first PHP function invoked is an include function. By including the FX.php document, you'll have access to the functions in the FX library. So, to use FX, all you do is upload FX.php to your Web server and include it at the top of each page you want to connect to a database.</strong></tt></span></p>
<p><span style="font-size:x-small;"><tt><strong>The next chunk of PHP code provides FX with parameters it must have to query the Web Companion. The IP address and port of the FileMaker Unlimited machine are specified as part of the instantiation of a new FX object, called $query here. (FX, by the way, is written using object-oriented techniques. PHP supports an object-oriented style, but doesn't mandate it.) The SetDBData function then specifies the database (and optionally, layout) to query. The two AddDBParam functions turn the user's entries from the search page into search arguments. Because you accessed this page as the result of a form submission, this page has access to all the form parameters submitted by the user. PHP stores this in an array called $_POST. </strong></tt></span></p>
<p><tt><strong></strong></tt></p>
<table border="0" width="350" align="right">
<tbody>
<tr valign="top">
<td width="717" align="center"><img src="/articles.nsf/1a2e28757f3e796d882569010066da17/ecda9f8222e5462988256d4e00619962/$FILE/STG53214/STG53214.gif!OpenElement" alt="" width="350" height="271" /></td>
</tr>
<tr valign="top">
<td width="717"><strong><em><span style="font-size:x-small;">Figure 3:</span></em></strong><strong><span style="font-size:x-small;"> </span></strong><strong><span style="font-size:x-small;color:#ff0000;">Finding Fred</span></strong><strong><span style="font-size:x-small;"> &#8212; The results of your search for &#8220;Flintstone.&#8221;</span></strong></td>
</tr>
</tbody>
</table>
<p><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><span style="font-size:x-small;">In the next line, you invoke the FMFind function and place the results in a variable called, aptly enough, $result. It's at this point that PHP makes a connection to FileMaker. FileMaker responds with a stream of XML (because that's the format PHP requests), and the FMFind function parses the incoming data and puts it into a big, multi-dimensional array. One of the items in that array contains the number of records returned by the query. You use a simple conditional statement to evaluate the number of records, then either output to the browser window a "No records found" message, or proceed to loop through the search results (using the foreach function) and output them to the screen. Figure 3 shows what the search results might look like after searching for "Flintstone" in the Employee database.</span></span></strong></tt></span></span></p>
<p><span style="font-size:x-small;"><tt><strong>With that, this simple example is complete. If you've never seen PHP code before, it might seem a bit strange at first. But really, if you have any experience with procedural or object-oriented programming, you'll pick up PHP syntax quickly.</strong></tt></span></p>
<p><span style="font-size:x-small;"><tt><strong>In addition to searching for records, you can use FX to submit requests to the Web Companion that will add, edit, or delete records from a database. You can also submit multiple requests in a single document. That's akin to using the inline functions of Lasso or CDML.</strong></tt></span></p>
<p><tt><strong><strong>Worth considering</strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong>I hope I've convinced you that PHP is worthy of your consideration as a Web development tool. PHP is powerful, fast, full-featured, well-supported, and easy to learn. To top it off, it's free. Drop Chris Hansen a note thanking him for his generous contribution to the FileMaker community.</strong></tt></span></p>
<p><tt><strong><strong>Resources</strong></strong></tt></p>
<p><span style="font-size:x-small;"><tt><strong>These resources will get you started with FX, PHP, and Web development in general.</strong></tt></span></p>
<p><span style="font-size:x-small;"><tt><strong><a href="http://www.iviking.org">http://www.iviking.org</a></strong></tt></span><span style="font-size:x-small;"><tt><strong> -- Chris Hansen's FX site.</strong></tt></span></p>
<p><span style="font-size:x-small;"><tt><strong><a href="http://www.php.net">http://www.php.net</a></strong></tt></span><span style="font-size:x-small;"><tt><strong> -- Includes installers, tutorials, and online documentation.</strong></tt></span></p>
<p><tt><strong><em><span style="font-size:x-small;">Advanced FileMaker Pro 6 Web Development</span></em><span style="font-size:x-small;">, by Bob Bowers and Steve Lane (Wordware Publishing, 2003). </span></strong></tt></div>
<div class="artbodybot">
<p><!-- m-art-body --></p>
<p><!--Sub2C--><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><br />
<!-- m-art-comments --><br />
<a name="_comments"></a> </span></strong></tt></span></span></p>
<div class="comments">
<h1><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;">Get Started with PHP</span></strong></tt></span></span></h1>
<h5><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><strong>No reader comments ... yet.</strong></span></strong></tt></span></span></h5>
</div>
<p><!-- m-art-comments --></p>
<p><!--Sub2D--><span style="font-size:x-small;"><span style="font-size:x-small;"><tt><strong><span style="font-size:x-small;"><br />
<!-- m-artcomment --><br />
</span></strong></tt></span></span></p>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div>Want to Build Website With PHP FIlemaker <a href="http://www.expertzweb.com">Expertzweb </a> can help you out</div>
<br />Posted in Latest News, Web Desigining Tagged: filemaker, filemaker tutorial, PHP, PHP Filemaker API Tutorial, PHP filemaker Integration, PHP tutorial, php tutorial filemaker web development, start php filemaker, tutorial, Web Development <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=53&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/09/get-started-with-php-in-filemaker-pro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
		<item>
		<title>FileMaker® API for PHP Tutorial</title>
		<link>http://expertzweb.wordpress.com/2008/10/09/filemaker%c2%ae-api-for-php-tutorial/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/09/filemaker%c2%ae-api-for-php-tutorial/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 11:51:35 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[X filemaker X PHP X PHP Filemaker API Tutorial X PHP filemaker Integration X start php filemaker]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/?p=51</guid>
		<description><![CDATA[Contents Introduction Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Introduction Welcome to the FileMaker API for PHP Tutorial This tutorial demonstrates key functionality of the FileMaker API for PHP. The tutorial consists of 6 lessons designed to teach you how to use the API to integrate a FileMaker Pro database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=51&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="sectionWrapper">
<h2>Contents</h2>
<p><a href="#introduction">Introduction</a><br />
<a title="Set up the API" href="#lesson1">Lesson 1</a><br />
<a title="Display container images" href="#lesson2">Lesson 2</a><br />
<a title="Add new records" href="#lesson3">Lesson 3</a><br />
<a href="#lesson4">Lesson 4</a><br />
<a href="#lesson5">Lesson 5</a><br />
<a href="#lesson6">Lesson 6</a></div>
<div class="sectionWrapper"><a name="introduction"></a></p>
<h2>Introduction</h2>
<h3>Welcome to the FileMaker API for PHP Tutorial</h3>
<p>This tutorial demonstrates key functionality of the  FileMaker API for PHP. The tutorial consists of 6 lessons designed to teach you how to use the API to integrate a FileMaker Pro database with a PHP web application. Each lesson  introduces a particular capability of the API, explaining how the  code is written and how it works.</p>
<p>The tutorial database is a FileMaker questionnaire system (questionnaire.fp7<em>). </em>Each questionnaire record can have multiple related questions. Each question can have multiple  related answers. Only one questionnaire is selected to be the <em>active </em>questionnaire. The active questionnaire is the one users are invited to take when using the PHP web application.<br />
When a user completes an online questionnaire, the system adds a<em> respondent</em> record for the user and adds the user&#8217;s answers as related records.</p>
<p>The tutorial completes a PHP web application gradually, each lesson building upon the previous lesson as follows:</p>
<ul>
<li> Lesson 1
<ul>
<li>Setting up the <em>FileMaker</em> database object
<ul>
<li class="comment"><em>What is necessary for me to prepare the FileMaker database object for use in my own custom web applications?</em></li>
</ul>
</li>
<li>Perform Find All
<ul>
<li class="comment"><em>How can I find all records in a database and display them on the web? </em></li>
</ul>
</li>
<li>Perform Find
<ul>
<li class="comment"><em>How can I find a particular record in the database and display it on the web? </em></li>
</ul>
</li>
</ul>
</li>
<li>Lesson 2
<ul>
<li>Display Container Images
<ul>
<li class="comment"><em>How can I display web-compatible images in container fields on my website? </em></li>
</ul>
</li>
<li>Use the ContainerBridge.php
<ul>
<li class="comment"><em>What is the </em>ContainerBridge.php<em> file and how does it work? </em></li>
</ul>
</li>
</ul>
</li>
<li>Lesson 3
<ul>
<li>Display FileMaker Value Lists
<ul>
<li class="comment"><em>How can I display FileMaker custom value lists on the web? </em></li>
</ul>
</li>
<li>Add  Records
<ul>
<li class="comment"><em>How do I add records to a FileMaker database from a submitted web form? </em></li>
</ul>
</li>
</ul>
</li>
<li>Lesson 4
<ul>
<li>Get Record by ID
<ul>
<li class="comment"><em>How can I retrieve a FileMaker record by its internal ID without performing another find? </em></li>
</ul>
</li>
<li>Get Related Set (Portal)
<ul>
<li class="comment"><em>How can I display records from a FileMaker portal on my website? </em></li>
</ul>
</li>
</ul>
</li>
<li>Lesson 5
<ul>
<li>Add Related Records
<ul>
<li class="comment"><em>How can I add  records to a portal from my website? </em></li>
</ul>
</li>
</ul>
</li>
<li>Lesson 6
<ul>
<li>Review of Get Related Set (Portal)
<ul>
<li class="comment"><em>How can I display records from a FileMaker portal on my website? </em></li>
</ul>
</li>
<li>Customize Format with Cascading Style Sheets<br />
(CSS)</p>
<ul>
<li class="comment"><em>How can I change the look of my HTML output using Cascading Style Sheets? </em></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>This tutorial doesn&#8217;t cover all of the API. However, after you complete these lessons, you will have a good foundation. To discover more about the API, see the FileMaker API for PHP documentation.</p>
<p>To view the FileMaker API for PHP documentation, go to the FileMaker Server Admin Console Start Page and click &#8220;PHP Site Assistant and XSLT Site Assistant Tools.&#8221; On the Web Publishing Tools page, click &#8220;FileMaker API for PHP Documentation.&#8221; Use the documentation as a reference while you complete this tutorial. This reference will help you discover how to use the FileMaker API for PHP more completely.</p>
<p>You should also become familiar with the questionnaire.fp7 database. Discover how it works and how questionnaires are built by creating questions with multiple  answers. Your knowledge of the questionnaire.fp7  design will be an integral part of understanding how the tutorial PHP application uses the API.</p>
<h3>Getting Started</h3>
<h4>Setup and Installation</h4>
<p class="h4_text">You must have FileMaker Server 9 installed and it must host the questionnaire.fp7 database. The tutorial folder must be hosted on the web server machine that is part of your FileMaker Server deployment.</p>
<p class="h4_text">For more information on the installation and deployment of FileMaker Server 9, see the <em>FileMaker Server Getting Started Guide.</em> For more information about the FileMaker API for PHP, see <em>FileMaker Server Custom Web Publishing with PHP. </em></p>
<h4>Suggested Knowledge and Skills</h4>
<p class="h4_text">You should be familiar with HTML programming. This includes HTML declarations, headers, and element tags. If you need more information on programming web pages with HTML, see the <a href="http://www.w3schools.com/xhtml/xhtml_dtd.asp">XHTML Tutorial at W3Schools</a>.</p>
<p class="h4_text">You should be familiar with PHP programming. This includes standard output, variables, arrays, conditional loops, objects,  methods, and functions. For more information on programming with PHP, see the <a href="http://www.w3schools.com/php/default.asp">PHP Tutorial at W3Schools</a>.</p>
<p class="h4_text">You should be comfortable using a text editor with HTML and PHP. This tutorial requires the use of a text editor to view and modify HTML and PHP code.</p>
<p class="h4_text">You should have a working knowledge of FileMaker Pro database design. This includes  fields, relationships, layouts, portals, and containers. For more information on designing databases with FileMaker Pro, see the FileMaker Pro documentation.</p>
<h4>Best Practices</h4>
<p class="h4_text">When editing records in FileMaker Pro, remember to <em>exit</em> or <em>commit</em> the record in order for changes to take effect. Web pages do not reflect changes entered into the database until the  record has been exited.</p>
<p class="h4_text">To view the PHP pages of each lesson in your web browser,  you must supply the fully qualified URL in order for the PHP code to execute. For example, if the files are  hosted on your local machine, point your browser to a URL that starts with  &#8220;http://localhost/&#8230;&#8221;. Do not use the local file path which may start with &#8220;file:///Volumes/&#8230;&#8221;. Using a &#8220;file://&#8221; URL results in the <strong>display</strong> of PHP code, not the <strong>execution</strong> of PHP code. Always make sure the URL begins with &#8220;http&#8221;, or &#8220;https&#8221; if you have set up SSL on your web server.</p>
</div>
<div class="sectionWrapper"><a name="lesson1"></a></p>
<h2>Lesson 1</h2>
<h3>Objective</h3>
<p>Lesson 1 details the essentials for using the FileMaker API for PHP in two PHP files: <span class="page">home.php</span> and <span class="page">dbaccess.php</span>. The <span class="page">home.php</span> file serves as a web browser starting point, and the <span class="page">dbaccess.php</span> file sets up a <em>FileMaker</em> object that represents the database. These pages  show  the basic steps for instantiating the <em>FileMaker</em> database object, setting its key properties, and performing a  find on the  <span class="database">questionnaire.fp7</span> database.</p>
<h3>Start</h3>
<p>To view the tutorial example,  direct your web browser to  <a href="www.expertzweb.com">home.php</a> located inside the Lesson1 folder. This page displays the welcome screen for the FileMaker Questionnaire System. When the page loads, a connection occurs behind the scenes between   PHP and the Web Publishing Engine, resulting in a found record from the <span class="database">questionnaire.p7</span> database.</p>
<p>Using your text editor, open  the file <span class="page">home.php</span> inside the Lesson1 folder. Locate the following  code just after the body tag.</p>
<p class="code">&lt;?php include (&#8220;dbaccess.php&#8221;); ?&gt;</p>
<p>This PHP statement includes, or <em>loads</em>, the <span class="page">dbaccess.php</span> file. The <span class="page">dbaccess.php</span> file contains functions which set up the <em>FileMaker </em>database object and prepare it for database operations. Consequently,  API methods in <span class="page">home.php</span> will not work  without it. Although the methods in <span class="page">dbaccess.php</span> could have been written in the <span class="page">home.php</span> file,   they have been separated for easier debugging and   maintenance.</p>
<h3>Set up the <em>FileMaker</em> Database Object</h3>
<p>The <span class="page">dbaccess.php</span> file contains  code for setting up the <em>FileMaker</em> database object. It plays a fundamental role in building the questionnaire application. Follow these steps to set up the <em>FileMaker </em>object:</p>
<ol>
<li>Load  the FileMaker API for PHP</li>
<li>Assign an instance of the <em>FileMaker</em> database class  to a variable</li>
<li>Set  key properties for the new <em>FileMaker</em> instance</li>
</ol>
<p>Using your text editor, open the file <span class="page">dbaccess.php</span> located in the  Lesson1 folder and follow the description of each step below.</p>
<h4 class="h4_text">1. Load the FileMaker API for PHP</h4>
<p class="h4_text">To use the FileMaker API, it must first be loaded into PHP memory.  This is done with the require statement.</p>
<p class="code">require_once (&#8216;FileMaker.php&#8217;);</p>
<p class="h4_text">Once loaded, you can create   instances of the <em>FileMaker</em> database class, using them for database connections in your web application.  An attempt to use the API without loading it first will result in an error.</p>
<h4 class="h4_text">2. Assign an instance of the <em>FileMaker</em> database class  to a variable</h4>
<p class="h4_text">An instance of the <em>FileMaker</em> database class must be created before it can be used. It must also be assigned to a variable to refer to it in the code.</p>
<p class="code">$fm = new FileMaker();</p>
<p class="h4_text">The above code creates an instance of the  <em>FileMaker</em> database object. It is referred to as the variable <em>$fm</em>.</p>
<h4 class="h4_text">3. Set key properties for the new <em>FileMaker</em> instance</h4>
<p class="h4_text">The <em>FileMaker</em> database object has a set of properties which can be set at any time. Some   properties, however, must be set before  database operations can occur. Here is the code which sets the  properties required for this tutorial.</p>
<p class="code">$fm-&gt;setProperty(&#8216;database&#8217;, &#8216;questionnaire&#8217;);</p>
<p>$fm-&gt;setProperty(&#8216;username&#8217;, &#8216;web&#8217;);</p>
<p>$fm-&gt;setProperty(&#8216;password&#8217;, &#8216;web&#8217;);</p>
<p class="h4_text"><strong>Note &#8211; </strong> The database name <em>questionnaire</em> does not need the <em>fp7 </em>extension added in the parameter.</p>
<p class="h4_text"><strong>Note &#8211; </strong>See the FileMaker API for PHP documentation for a list of  the <em>FileMaker</em> database class properties and their descriptions.</p>
<p>The <span class="page">dbaccess.php</span> file contains very little code, but  it effectively prepares the <em>Filemaker</em> object  for use. After the file is loaded, the <em>FileMaker </em>object  is useable as the variable $fm and  key properties are set to their required values. The <span class="page">dbaccess.php</span> file enables the <span class="page">home.php</span> file to communicate with the <span class="database">questionnaire.fp7</span> database.</p>
<h3>Perform Find, Perform Find All</h3>
<p>The  <span class="page">home.php</span> file performs two database operations: <em>Find All</em> (Show All Records) and <em>Find</em>. To view the code for these operations, open the <span class="page">home.php</span> file in your text editor. To view the database for these operations, open  the <span class="database">questionnaire.fp7</span> file that you hosted on  FileMaker Server.</p>
<h4 class="h4_text">1. Find All (Show All Records)</h4>
<p class="h4_text">The <span class="database">questionnaire.fp7</span> database contains a layout called <em>Active Questionnaire</em>. This layout serves as an interface; it contains only one record in the table. On this layout,  users  select which questionnaire is the <em>active</em> questionnaire. The web application  needs to retrieve the ID of this <em>active</em> questionnaire.</p>
<p class="h4_text">The active questionnaire ID  is retrieved by performing a Find All (Show All Records) on the layout <em>Active Questionnaire. </em>This operation  uses the  command object  <em>FileMaker_Command_FindAll</em>.</p>
<p class="h4_text"><strong>Note -</strong> See the FileMaker API for PHP documentation for a list of  command objects and their methods.</p>
<p class="h4_text">An instance of the FileMaker_Command_FindAll object is created by having the $fm (<em>FileMaker</em> database  instance) execute its <em>newFindAllCommand()</em> method, specifying (in  parenthesis)  the name of the layout <em>Active Questionnaire. </em>The layout determines  which table occurrence is used (context)  and which fields  are returned (results).</p>
<p class="h4_text">The <em>FileMaker_Command_FindAl</em><em>l </em> instance  must be assigned to a variable as the following example shows.</p>
<p class="code">$findCommand = $fm-&gt;newFindAllCommand(&#8216;Active Questionnaire&#8217;);</p>
<p class="h4_text">The above code assigns a new FileMaker_Command_FindAll object to the variable <em>$findCommand</em>. The  Find All command is performed with the <em>execute() </em>method. The find results must be assigned to a variable.</p>
<p class="code">$result = $findCommand-&gt;execute();</p>
<p class="h4_text">It is possible, after executing a command, that an error will occur. If an error does occur (or no matching records are found), the $result variable is assigned a <em>FileMaker_Error object</em>. Use the following code  to check for the FileMaker_Error object. The error message is displayed by using the <em>getMessage()</em> method.</p>
<p class="code">if (FileMaker::isError($result)) {</p>
<p>echo &#8220;&lt;p&gt;Error: &#8221; . $result-&gt;getMessage() . &#8220;&lt;/p&gt;&#8221;;</p>
<p>exit;</p>
<p>}</p>
<p class="h4_text">If no error has occurred, the variable <em>$result</em> contains an array of FileMaker_Record objects, one for every record in the found set. Use the $result variable to retrieve the first record in the Find All result. Because PHP arrays are indexed  numerically by default,  you can get the first record by using the following code.</p>
<p class="code">$record = $records[0];</p>
<p class="h4_text">This code assigns a FileMaker_Record  object containing the first record in the found set to the variable <em>$record</em>. You can retrieve the contents of the questionnaire_id from this record by using the <em>getField()</em> method. The results of the<em> getField()</em> method must be assigned to a variable.</p>
<p class="code">$active_questionnaire_id =  $record-&gt;getField(&#8216;questionnaire_id&#8217;);</p>
<p class="h4_text">This variable now contains the ID of the active questionnaire. The next step uses this variable as a parameter in the next find.</p>
<p class="h4_text"><strong>Note -</strong> See the FileMaker API for PHP documentation for a list of objects and their methods.</p>
<h4 class="h4_text">2. Find</h4>
<p class="h4_text">Now that you have the ID of the active questionnaire, you can use it to <em>Find</em> the  questionnaire record. The code for performing this operation is located near the bottom of the <span class="page">home.php</span> file. The operation uses the  command object  <em>FileMaker_Command_Find</em>.</p>
<p class="h4_text">An instance of the FileMaker_Command_Find is created by having the $fm (<em>FileMaker</em> database  instance) execute its <em>newFindCommand()</em> method, specifying (in  parenthesis)  the name of the layout <em>Active Questionnaire. </em>The layout determines  which table occurrence is used in the find and which fields  are returned in the results.</p>
<p class="h4_text">The <em>FileMaker_Command_Find</em><em> </em> instance  must be assigned to a variable as the following example shows.</p>
<p class="code">$findCommand =&amp; $fm-&gt;newFindCommand(&#8216;questionnaire&#8217;);</p>
<p class="h4_text">To add criteria to the find,   use the <em> addFindCriterion()</em> method. The <em>addFindCriterion()</em> method takes two parameters: <em>fieldName </em>and <em>searchParameter</em>. Pass the &#8220;Questionnaire ID&#8221; field name (as defined in FileMaker Pro) and the variable <em>$active_questionnaire_id</em> as  parameters.</p>
<p class="code">$findCommand-&gt;addFindCriterion(&#8216;Questionnaire ID&#8217;, $active_questionnaire_id);</p>
<p class="h4_text"><strong>Note &#8211; </strong>The <em>addFindCriterion()</em> method can be called multiple times, simulating the logical AND  which  occurs when entering multiple find criteria into a single find request within FileMaker Pro.</p>
<p class="h4_text">After  the find criteria have been added, the <em>execute()</em> method  is used to perform the find. The results of the <em>execute()</em> method must be assigned to a variable.</p>
<p class="code">$result = $findCommand-&gt;execute();</p>
<p class="h4_text">The  $result variable  now contains an array of FileMaker_Record objects. Because the find was performed on the layout <em>questionnaire</em>, each   record  in   <em>$result</em> contains  the values for every field on the <em>questionnaire</em> layout.</p>
<p class="h4_text">The final code in this page uses  PHP echo statements and the  <em>getField()</em> method to output the <em>Questionnaire Name</em> and <em>Description</em> fields on the <span class="page">home.php</span> page.</p>
</div>
<div class="sectionWrapper"><a name="lesson2"></a></p>
<h2>Lesson 2</h2>
<h3>Objective</h3>
<p>Lesson 2 covers the  code required to display FileMaker Pro container images on the web.  If you store web-compatible images in a FileMaker Pro database, you can use the FileMaker API for PHP to retrieve those images and display them on your web site.</p>
<h3>Start</h3>
<p>Open the FileMaker API Tutorial database <span class="database">questionnaire.fp7 and m</span>ake sure that the active questionnaire has a web compatible image in the container field.  Next, view the PHP tutorial example by opening the Lesson2 <a href="www.expertzweb.com">home.php</a> file in your web browser. Notice the page displays the image of the active questionnaire. Try changing the container image in the FileMaker database. Make sure you exit the record when you are done. Refresh your browser and watch the website update with the new image.</p>
<h3>Display  Container Image</h3>
<p>To see how the API is used for this operation, open  the file <span class="page">home.php</span> in the folder Lesson2. View the last PHP statements in the file, paying particular attention to the &lt;img&gt; (image) tag and its <em>src</em> (source) attribute.</p>
<p>Please note the following points regarding this  technique.</p>
<ol>
<li>The container field <em>Graphic</em> is on the layout <em>questionnaire</em> (which is the layout of the previous find). Remember, only values from fields on the <strong>layout used for the find</strong> are returned to the API.</li>
<li>The value of the <em>Graphic </em> field returned is <strong>not an image</strong>, but a special URL which requests the image from the Web Publishing Engine.</li>
</ol>
<p class="code">echo &#8216;&lt;img src=&#8221;ContainerBridge.php?path=&#8217; . urlencode($record-&gt;getField(&#8216;Graphic&#8217;)) . &#8216;&#8221;&gt;&#8217;;</p>
<p>Because an HTML &lt;img&gt; (image) tag must have a <em>file path</em> as its <em>src </em>(source)  attribute, this lesson uses a separate file to actually retrieve the image. The file that retrieves the container image is called <span class="page">ContainerBridge.php</span>, and its filename appears inside  the <em>src</em> (source) attribute of the &lt;img&gt; (image) tag.</p>
<p>The  <span class="page">ContainerBridge.php</span> file does not know which image you want displayed. To specify the image, you must append the <em>Graphic</em> field value to the end of the <em>src </em>(source) URL. In HTML, this is called the GET method.</p>
<p>Using a <em>name/value</em> pair, and starting with a question mark, concatenate the desired string. The <em>name</em> is set to &#8220;path&#8221; and the <em>value</em> is set to the <em>getField() </em>method result, passing the name of the container field <em>(Graphic)</em> in parenthesis.</p>
<p><strong>Note &#8211; </strong>The <em>getField() </em>result is passed to the PHP urlencode() function to ensure that special characters are correctly encoded for a URL.</p>
<h3>Using ContainerBridge.php</h3>
<p>Using your text editor,  open  the file <span class="page">ContainerBridge.php</span> in the Lesson2 folder. This simple script uses the <em>getContainerData()</em> FileMaker_Record  method to retrieve the actual image.</p>
<p>For <em>getContainerData()</em> to work, you must pass the field results from <em>getField()</em> (of a container field) to the <em>getContainerData()</em> method in parenthesis. In <span class="page">home.php</span>, the result from getField() for the <em>Graphic</em> field was passed through the URL. In <span class="page">ContainerBridge.php</span>, the result is retrieved from the URL via the <em>path</em> element of the $_GET array and passed to the <em>getContainerData()</em> method.</p>
<p class="code">echo $fm-&gt;getContainerData($_GET['path']);</p>
<p>The <span class="page">ContainerBridge.php</span> file simple retrieves the path of the specified image from the FileMaker Pro database so that the <span class="page">home.php</span> file can use it in the &lt;img&gt; tag to display the image in the web browser.</p>
<p><strong>Note &#8211; </strong>See the FileMaker API for PHP documentation for a list of FileMaker_Record object methods.</div>
<div class="sectionWrapper"><a name="lesson3"></a></p>
<h2>Lesson 3</h2>
<h3>Objective</h3>
<p>Lesson 3 covers the  code required to create  a dynamic web form using FileMaker layout objects. It also discusses the  code required for adding a new FileMaker record from a web form submission. This lesson uses two additional PHP  files: <span class="page">Respondent.php</span> and <span class="page">handle_form.php</span>. The <span class="page">Repondent.php</span> file serves to dynamically generate a web form, while the <span class="page">handle_form.php</span> file is used to  validate form entries and enter them into the <span class="database">questionnaire.fp7</span> database as a new record.</p>
<h3>Start</h3>
<p>Open the questionnaire web site by pointing your browser to the  <a href="www.expertzweb.com">home.php</a> file in the Lesson3 folder. This version of the page displays a <em>Continue</em> button for you to start the questionnaire application. When you click the Continue button, you are redirected  to the <span class="page">Respondent.php</span> file. Enter your information into the web form and click <em>Submit</em>; retry if you did not enter enough information. When your form validates, you see the Thank You message and the information you entered is added to the <span class="database">questionnaire.fp7</span> database as a new record.</p>
<h3>Retrieve Value List Items</h3>
<p>To view how this application works, open  the <span class="page">Respondent.php</span> page in your text editor. Note that the<span class="sectionWrapper"> </span><span class="page">dbaccess.php</span> file is included near the top. As  discussed in Lesson 1, this include statement  ensures that you have an instance of the <em>FileMaker</em> database class, and that the instance can be used as the variable <em>$fm</em>.</p>
<p>Notice the <span class="page">Respondent.php</span> radio button form element called &#8220;prefix&#8221;. This element derives its values from the questionnaire.fp7 FileMaker Pro database by using its value list of the same name. This technique allows you to build a dynamic form element based on a value list defined in the FileMaker database. In this way, you don&#8217;t have to update your PHP code every time the value list changes in the database. This technique is implemented in the following steps:</p>
<ol>
<li>Retrieve a layout object via the <em>getLayout() </em>method (passing the layout name in parenthesis)
<ul>
<li>The <em>getLayout()</em> method returns a FileMaker_Layout object</li>
</ul>
</li>
<li>Retrieve the value list values via the <em>getValueList()</em> method
<ul>
<li><em>getValueList() </em> is a method of the FileMaker_Layout object</li>
</ul>
</li>
<li>Loop through the  array of values and output each as a radio button</li>
</ol>
<p>When using this technique, remember that the  layout specified must contain a field <em>which is formatted</em> by the value list specified. If a value list is requested with the <em>getValueList()</em> method, and the value list has not been formatted to any field on the layout specified with  <em>getLayout()</em>, an error will result. Here is the code which is used to display the dynamic radio buttons.</p>
<p class="code">$layout =&amp; $fm-&gt;getLayout(&#8216;Respondent&#8217;);<br />
$values = $layout-&gt;getValueList(&#8216;prefixes&#8217;);<br />
foreach($values as $value){</p>
<p>echo &#8216;&lt;input type= &#8220;radio&#8221; name= &#8220;prefix&#8221; value= &#8220;&#8216;. $value .&#8217;&#8221;&gt;&#8217; . $value . &#8216; &#8216;;<br />
}</p>
<p><strong>Note &#8211; </strong>See the FileMaker API for PHP documentation for a list of FileMaker_Layout object methods.</p>
<p><strong>Note -</strong> The form in <span class="page">Respondent.php</span> also contains several hidden form elements. One  named &#8220;active_questionnaire_id&#8221;  contains the questionnaire ID from <span class="page">home.php</span>. This form passes  the ID into <span class="page">handle_form.php</span> where it will be used in Lesson 4.</p>
<h3>Add New Record</h3>
<p>When the <span class="page">Respondent.php</span> form has submitted the data, values are passed to the action page <span class="page">handle_form.php</span> via the POST method. Using your text editor, open the <span class="page">handle_form.php</span> file  located in the Lesson3 folder.</p>
<p>Notice that the user-submitted data is assembled into an  array and assigned to the variable <em>$respondent_data</em>. In this associative array,  the <em>Key</em> for each element is the exact name of the FileMaker field that the data is to be posted to. The <em>Value</em> of each element  corresponds to the values submitted from the HTML form element within the $_POST array. This $respondent_data array is used by the <em>FileMaker</em> object  when creating the database record.</p>
<p>After assembling the data array, the PHP code performs some simple validation checks. These validation methods  use  PHP code explicitly; there is no validation performed by FileMaker Server during this operation.</p>
<p>After the  user data passes validation, a new record can be created in two simple steps:</p>
<ol>
<li>Create a new FileMaker_Command_Add object, passing two parameters:
<ul>
<li>layout name (the layout must have the necessary fields on it)</li>
<li>data array <em>($respondent_data)</em></li>
</ul>
</li>
<li>Add the record with the <em>execute() </em>method</li>
</ol>
<p class="code">$newRequest =&amp; $fm-&gt;newAddCommand(&#8216;Respondent&#8217;, $respondent_data);<br />
$result = $newRequest-&gt;execute();</p>
<p>Remember, when creating a new FileMaker_Command_Add object, you must specify the name of the layout. The layout name determines  which table occurrence is used (context)  and which fields are returned (results). The fields used to enter data  must be on the  layout.</p>
<p>In Lesson 4, the <span class="page">handle_form.php</span> page will be augmented to use the added record and display the first question.</div>
<div class="sectionWrapper"><a name="lesson4"></a></p>
<h2>Lesson 4</h2>
<h3>Objective</h3>
<p>Lesson 4 covers the  code required to retrieve a FileMaker record by its ID and retrieve related records from a portal. Portals are powerful controls used in FileMaker Pro solutions. The FileMaker API for PHP has special methods designed to work with portal data. This lesson introduces some of that functionality.</p>
<h3>Start</h3>
<p>Open  the FileMaker Pro <span class="database">questionnaire.fp7</span> database which is  hosted on FileMaker Server. Click the <em>Edit Questionnaire</em> button and make sure the active questionnaire has at least one record in the <em>Question</em> portal.   Then open the Lesson4 <a href="www.expertzweb.com">home.php</a> file in your web browser. Select the <em>Continue</em> button and enter your respondent information.</p>
<p>Next  you are prompted with the first question of the active questionnaire. Open  the FileMaker Pro <span class="database">questionnaire.fp7</span> database again. Locate the first question of the active questionnaire. Try changing the first question type. Click the<em> Edit Answers</em> button and add  possible  answers. Refresh your web browser to see the updated question.</p>
<p>This lesson introduces two new tasks you can perform: get a record by its ID and retrieve a set of related records from a portal.</p>
<h3>Find Record by ID</h3>
<p>With your text editor, open the <span class="page">handle_form.php</span> file located inside the Lesson4 folder. Scroll down  a third of the file to where the <span class="page">handle_form.php</span> file ended in Lesson 3. Notice  that this lesson adds code that requests the record object of the new respondent record. This request is necessary because the <em> Respondent ID </em>field  is defined with the <em>Auto Enter Serial Number</em> option in FileMaker Pro and you need to retrieve the<em> Auto Enter </em>number.</p>
<p>As with <em>Find</em> functions in Lesson 1, a   new record can be retrieved  by using the<em> getRecord() </em>and <em>getField()</em> methods.</p>
<p class="code">$records = $result-&gt;getRecords();<br />
$record = $records[0];<br />
$respondent_recid = $record-&gt;getField(&#8216;Respondent ID&#8217;);</p>
<p>The next task is  to retrieve the active questionnaire  name. To accomplish this, use the <em>getRecordById()</em> method of the FileMaker instance <em>($fm)</em>.</p>
<p>When using  <em>getRecordById()</em>,   pass the internal FileMaker record ID and the name of the layout. The layout  determines  which table occurrence (context) is used and which field values (results) are  returned. The code in this page passes the <em>active_questionnaire_id</em> of the $_POST array sent to this file from the respondent form of <span class="page">Respondent.php</span>.</p>
<p class="code">$active_questionnaire_id = $_POST['active_questionnaire_id'];</p>
<p>$active_questionnaire = $fm-&gt;getRecordById(&#8216;questionnaire&#8217;,$active_questionnaire_id);<br />
$questionnaire_name = $active_questionnaire-&gt;getField(&#8216;Questionnaire Name&#8217;);</p>
<p><strong>Note &#8211; </strong>Every  record object returned from an API operation  contains the  internal FileMaker record ID which can be retrieved with the <em>getRecordId()</em> method.</p>
<p>The next task is to retrieve the questionnaire records and display the first question. Search for all questions  which match the active questionnaire ID. This find is performed against the Questions layout.</p>
<p class="code">$findCommand =&amp; $fm-&gt;newFindCommand(&#8216;Questions&#8217;);<br />
$findCommand-&gt;addFindCriterion(&#8216;Questionnaire ID&#8217;, $active_questionnaire_id);<br />
$result = $findCommand-&gt;execute();<br />
$records = $result-&gt;getRecords();<br />
$question = $records[0];</p>
<h3>Get Related Set</h3>
<p>The questionnaire database is designed so that each  question has a specific type (<em>for example, text, radio, and checkbox)</em>. If the type is for a multiple choice answer, each question can have multiple answer choices. The layout <em>Questions</em> contains a portal which displays   the possible  answers. If a question has one or more  answers, the following code displays the answer choices using the &#8220;type&#8221; specified.</p>
<p>To explain this code,  assume that the question is of type <em>radio</em>. Scroll down the <span class="page">handle_form.php</span> document until you see the <em>else if </em>condition which checks for <em>radio or ranking</em> question types.</p>
<p class="code">else if ($question_type ==&#8221;radio&#8221; || $question_type ==&#8221;ranking&#8221;)</p>
<p>If the condition is true, the following code retrieves the related answer choices and displays them as radio button form elements. Answer  records from the portal can be retrieved by using the <em>getRelatedSet()</em> method of the FileMaker_Record object.</p>
<p>When calling the <em>getRelatedSet()</em> method, the <strong>name of the related table </strong> must be passed in parenthesis and <strong>the portal defined</strong> with this relationship must be on the layout used when retrieving the <em>$question</em> record.</p>
<p class="code">$relatedSet = $question-&gt;getRelatedSet(&#8216;question_answers&#8217;);</p>
<p>The variable <em>$relatedSet</em> now contains an array of record objects from the related portal. Loop through the array and output the field values for each record found.</p>
<p class="code">foreach ($relatedSet as $relatedRow)<br />
{<br />
$possible_answer = $relatedRow-&gt;getField(&#8216;question_answers::answer&#8217;);<br />
echo &#8216;&lt;input type= &#8220;radio&#8221; name= &#8220;radio_answer&#8221; value= &#8220;&#8216;. $possible_answer .&#8217;&#8221;&gt;&#8217; . $possible_answer . &#8216;&lt;br/&gt;&#8217;;<br />
}</p>
<p>You could have retrieved the related records by performing a find, but it is much easier to use <em>getRelatedSet()</em> using a portal that already contained  the related set.</div>
<div class="sectionWrapper"><a name="lesson5"></a></p>
<h2>Lesson 5</h2>
<h3>Objective</h3>
<p>Lesson 5 covers the  code necessary to add related records. If you have a portal defined on a layout which allows creation of related records, you can use the FileMaker API for PHP to add related records from the web.</p>
<h3>Start</h3>
<p>Open  your web browser to  the <a href="www.expertzweb.com">home.php</a> page being hosted in the Lesson5 directory. Click the <em>Continue</em> button and  complete the online survey. Open the FileMaker questionnaire.fp7 database which is  hosted on FileMaker Server. From the Active Questionnaire select the <em>Review Responses </em>button and navigate to the last record in the table. This record contains the respondent information you entered. Each answer  is saved as a  record in the <em>Responses</em> portal.</p>
<h3>Add Related Record (Portal Rows)</h3>
<p>Adding portal rows with the FileMaker API for PHP can be done in four steps:</p>
<ol>
<li>Start with a valid record object</li>
<li>Create a new blank related record</li>
<li>Add data to the fields of the new record <em>(optional)</em></li>
<li>Commit the new  record</li>
</ol>
<h4>Start with a Valid Record Object</h4>
<p class="h4_text">With your text editor, open the <span class="page">handle_form.php</span> file located in the Lesson5 tutorial folder. Scroll down and look for the code which retrieves the respondent record:</p>
<p class="code">$respondent_rec = getRespondentRecordFromRespondentID($respondent_recid);</p>
<p class="h4_text">This code uses a function which has been added to the <span class="page">dbaccess.php</span> file. If you open the <span class="page">dbaccess.php</span> in your text editor, you can see this function&#8217;s definition near the bottom. Inside the function definition notice that the <em>newFindCommand() </em>method uses the <em>Respondent</em> layout for its context <em>.</em></p>
<p class="code">$find = $fm-&gt;newFindCommand(&#8216;Respondent&#8217;);</p>
<p class="h4_text">This function assigns the respondent record object to the <em>$respondent_rec</em> variable. The variable is   referenced to the layout <em>Respondent</em> because that layout was the context of the find command<em>. </em>Therefore any methods used by the <em>$respondent_rec </em>variable   start from the context of the <em>Respondent </em>layout.</p>
<h4>Create a New Blank Related Record</h4>
<p class="h4_text">Going back to the <span class="page">handle_form.php</span> file, the next line of code begins to create the new related record.</p>
<p class="code">$new_response = $respondent_rec-&gt;newRelatedRecord(&#8216;Responses&#8217;);</p>
<p class="h4_text">When this line executes, the variable <em>$new_response</em> is assigned a <strong>blank</strong> record object (a new record has not yet been created in the FileMaker database).</p>
<p class="h4_text">It is important to understand the context of this operation. This code starts from the layout of the calling record object (<em>Responses)</em> and specified the relationship of a portal on that layout. Then the code passes the related table name to the   <em>newRelatedRecord()</em> method.</p>
<h4>Add Data to the Fields of the Blank Record <em>(optional)</em></h4>
<p class="h4_text">After you  have a new blank  record and  know which portal context that the record belongs to, you can begin entering data with the <em>setField()</em> method. This method takes two parameters: <em>field</em> <em>name</em> and <em>field value</em>. Because this is a related record, the field name must be expressed with the relationship name <strong>and</strong> the field name separated by two colons.</p>
<p class="code">$new_response-&gt;setField(&#8216;Responses::Question ID&#8217;, $cur_question);<br />
$new_response-&gt;setField(&#8216;Responses::Response&#8217;, $translatedAnswer);</p>
<p class="h4_text">After you  have created the new related record and  have added data to the appropriate fields, you are ready to commit the entry.</p>
<p class="h4_text"><strong>Note &#8211; </strong>It is not necessary to set field data before committing a new blank record.</p>
<h4>Commit the New Record</h4>
<p class="h4_text">No new record objects are created in the FileMaker database until they have been committed. The <em>commit()</em> method   inserts  the <em>FileMaker_Record</em> object into the questionnaire.fp7 FileMaker database.</p>
<p class="code">$result = $new_response-&gt;commit();</p>
<p class="h4_text">The <em>$result </em>variable is now assigned the FileMaker_Record object of the new record, and the new record has been created in the FileMaker database. If an error occurs, the variable <em>$result</em> contains a FileMaker_Error object. It is good practice to check for errors after executing the <em>commit()</em> method.</p>
</div>
<div class="sectionWrapper"><a name="lesson6"></a></p>
<h2>Lesson 6</h2>
<h3>Objective</h3>
<p>Lesson 6 reviews the   code necessary for displaying related fields from a portal.  It also introduces the basic instructions for using  Cascading Style Sheets (CSS) to modify the appearance of your web application.</p>
<h3>Start</h3>
<p>Open  your web browser to  the <a href="www.expertzweb.com">home.php</a> page  hosted in the Lesson6 directory. Notice the new <em>look</em> of the site. This formatting comes from a separate CSS  page.  CSS styles can be used to format  HTML code used in your web application and are discussed at the end of this lesson.</p>
<p>Click the <em>Continue</em> button and  complete the online survey. Notice that the <span class="page">thankyou.php</span> page displays a summary of the questions you answered. These questions and responses are from a portal on the<em> Respondent</em> layout in the <span class="database">questionnaire.fp7</span> database.  If a FileMaker layout  contains portal data, it can be displayed on the web using  the FileMaker API for PHP.</p>
<h3>Get Related Sets</h3>
<p>Using your text editor, open the <span class="page">thankyou.php</span><span class="sectionWrapper"> page</span> which is located in the Lesson6 directory. Scroll  to the end of the file and locate the last HTML table.</p>
<p>Notice the code  above the table which retrieves the respondent record.</p>
<p class="code">$respondent_record = getRespondentRecordFromRespondentID($respondent_recid);</p>
<p>The<em> getRespondentRecordFromRespondentID() </em>function is defined in the <span class="page">dbaccess.php page</span>. Its context is the <em>Respondent</em> layout in the <span class="database">questionnaire.fp7</span> database.</p>
<p>Looking inside the  HTML table,  note that the <em>$respondent_record</em> variable is used to retrieve the set of related records. This is accomplished  by using the <em>getRelatedSet()</em> method. To use the <em>getRelatedSet()</em> method, you must specify the related table name of the desired portal and the desired portal must be on the <em>Respondent</em> layout.</p>
<p class="code">$response_related_set = $respondent_record-&gt;getRelatedSet(&#8216;Responses&#8217;);</p>
<p>The above code  assigns   an array which contains the records from the portal <em>Responses</em> to the variable <em>$response_related_set</em>. Each response is  a FileMaker_Record object. This code uses the <em>getField()</em> method of the FileMaker_Record object  to output the portal rows in an HTML table. Remember to use the full name of the related table <strong>and</strong> field name separated by two colons when you output related fields.</p>
<p>Here is the loop which displays the related set in HTML.</p>
<p class="code">foreach ($response_related_set as $response_related_row)</p>
<p>{</p>
<p>$question = $response_related_row-&gt;getField(&#8216;Questions 2::question&#8217;);</p>
<p>$answer = $response_related_row-&gt;getField(&#8216;Responses::Response&#8217;);<br />
//converts any line returns in the answer to commas<br />
$answer = str_replace(&#8220;\n&#8221;,&#8221;, &#8220;,$answer);<br />
echo &#8216;&lt;tr&gt;&lt;td&gt;&#8217; . $question . &#8216;&lt;/td&gt;&#8217;;<br />
echo &#8216;&lt;td&gt;&#8217; . $answer . &#8216;&lt;/td&gt;&lt;/tr&gt;&#8217;;</p>
<p>}</p>
<h3>Formatting with CSS</h3>
<p>You can format your web applications using Cascading Style Sheets (CSS). With your text editor, open the <span class="page">style.css</span> file located inside the Lesson6 folder and review the styles   defined for some of the HTML tags. CSS styles can be applied to any HTML tag, allowing you to format multiple items on multiple pages from a single definition.</p>
<p>To apply formatting to a specific HTML tag, you must declare the tag name. Following the tag name, you must state the style attributes enclosed in curly braces. As in PHP, each statement must be terminated by a semi-colon.</p>
<p class="code">body {<br />
background-color: #333333;<br />
padding: 20px;<br />
color: #ffffff;<br />
font-family:Verdana, Arial, Helvetica, sans-serif;<br />
}</p>
<p>After you have created a CSS file, you can apply it to  any HTML or PHP document. To apply external styles, you must include or <em>link</em> the  style sheet to your document: use the &lt;link&gt; (link) tag in the header  of your HTML output.</p>
<p>With your text editor,  open the <span class="page">thankyou.php</span> file located in the Lesson6 folder.  Inside the header tags, notice the<em> &lt;</em>link&gt; (link) tag which tells the web browser to apply the <span class="page">style.css</span> formatting. When using the &lt;link&gt; tag,  be sure to supply the correct path or <em>href </em>to your CSS page.</p>
<p class="code">&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;style.css&#8221; /&gt;</p>
<p>Style sheets can be used in multiple applications and each application can use multiple style sheets. For more information on CSS styles and  their attributes visit the <a href="http://www.w3schools.com/css/css_reference.asp">CSS2 reference at W3Schools</a>.
</div>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Uncategorized Tagged: X filemaker X PHP X PHP Filemaker API Tutorial X PHP filemaker Integration X start php filemaker <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=51&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/09/filemaker%c2%ae-api-for-php-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started: Ajax</title>
		<link>http://expertzweb.wordpress.com/2008/10/08/getting-started-ajax/</link>
		<comments>http://expertzweb.wordpress.com/2008/10/08/getting-started-ajax/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 18:17:54 +0000</pubDate>
		<dc:creator>Miracle Studios</dc:creator>
				<category><![CDATA[Latest News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax development]]></category>
		<category><![CDATA[ajax getting started]]></category>
		<category><![CDATA[ajax overview]]></category>
		<category><![CDATA[ajax programming]]></category>
		<category><![CDATA[ajax start]]></category>
		<category><![CDATA[overview of ajax]]></category>
		<category><![CDATA[start ajax]]></category>

		<guid isPermaLink="false">http://expertzweb.wordpress.com/2008/10/08/getting-started-ajax/</guid>
		<description><![CDATA[The foundation that makes Ajax possible is the communication layer with the server. The most complete option for performing this communication is the JavaScript XMLHttpRequest object. If XMLHttpRequest is not suitable to you, hidden IFrames and cookies can also be used. We will examine both options later in this chapter. This chapter introduces you to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=50&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--[if !mso]&gt;-->  <!--[endif]--><!--[if gte mso 9]&gt;  Normal 0   &lt;![endif]--> The foundation that makes Ajax possible is the communication layer with the server. The most complete option for performing this communication is the JavaScript <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> object. If <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> is not suitable to you, hidden <code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code>s and cookies can also be used. We will examine both options later in this chapter.</p>
<p>This chapter introduces you to the <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
object, showing you how to work around its implementation differences<br />
between browsers. After that, we make some actual page requests, both<br />
in a synchronous fashion and in an asynchronous fashion. This chapter<br />
finishes with some various fallback approaches that can be used if a<br />
browser doesn’t support <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>, including how to use <code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code>s and cookies as your communication channel.</p>
<h2>2.1 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> Overview</h2>
<p>Originally, Microsoft designed <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> to allow Internet Explorer (IE) to load XML documents from JavaScript. Even though it has XML in its name, <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> really is a generic HTTP client for JavaScript. With it, JavaScript can make <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> and <code><span style="font-size:10pt;font-family:&quot;">POST HTTP</span></code> requests. (For <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> requests, data can be sent to the server in a format of your choosing.) The main limitations to <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
are due to the browser security sandbox. It can make only HTTP(S)<br />
requests (file URLs, for example, won’t work), and it can make requests<br />
only to the same domain as the currently loaded page.</p>
<p>The security limitations of <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> do limit<br />
the ways in which you can use it, but the trade-off in added security<br />
is well worth it. Most attacks against JavaScript applications center<br />
around injecting malicious code into the Web page. If <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
allowed requests to any Web site, it would become a major player in<br />
these attacks. The security sandbox reduces these potential problems.<br />
In addition, it simplifies the programming model because the JavaScript<br />
code can implicitly trust any data it loads from <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>. It can trust the data because the new data is just as secure as the page that loaded the initial page.</p>
<p>Despite the fact that <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> provides only a<br />
small API and just a handful of methods and properties, it has its<br />
differences between browsers. These differences are mainly in event<br />
handling and object instantiation (in IE, <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest </span></code>is actually an ActiveX object), so they aren’t hard to work around. In the following overview of the <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> API, the Mozilla syntax for <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> instantiation is used. If you want to run the examples in IE, you need to replace <code><span style="font-size:10pt;font-family:&quot;">new XMLHttpRequest();</span></code> with either <code><span style="font-size:10pt;font-family:&quot;">new</span></code> <code><span style="font-size:10pt;font-family:&quot;">ActiveXObject("MSXML2.XMLHTTP.3.0");</span></code> or the full cross-browser instantiation method shown in the “Cross-Browser <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>” section of this chapter.</p>
<p><code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest </span></code>is the most-used method for Ajax<br />
communications because it provides two unique features. The first<br />
feature provides the ability to load new content without that content<br />
being changed in any way, which makes it extremely easy to fit Ajax<br />
into your normal development patterns. The second feature allows<br />
JavaScript to make synchronous calls. A synchronous call stops all<br />
other operations until it’s complete, and while this isn’t an option<br />
that is usually used, it can be useful in cases in which the current<br />
request must be completed before further actions are taken.</p>
<h3>2.1.1 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest::Open()</span></code></h3>
<p>The <code><span style="font-size:10pt;font-family:&quot;">open</span></code> method is used to set the request type (<code><span style="font-size:10pt;font-family:&quot;">GET, POST, PUT</span></code>, or <code><span style="font-size:10pt;font-family:&quot;">PROPFIND</span></code>),<br />
the URL of the page being requested, and whether the call will be<br />
asynchronous. A username and password for HTTP authentication can also<br />
be optionally passed. The URL can be either a relative path (such as <code><span style="font-size:10pt;font-family:&quot;">page.html</span></code>) or a complete one that includes the server’s address (such as <a href="http://www.miraclestudios.us/">http://www.miraclestudios.us/</a>)The basic method signature is:</p>
<pre>open(type,url,isAsync,username,password)</pre>
<p>In the JavaScript environment, security restrictions are in place. These security restrictions cause the <code><span style="font-size:10pt;font-family:&quot;">open </span></code>method to throw an exception if the URL is from a different domain than the current page. The following example uses <code><span style="font-size:10pt;font-family:&quot;">open</span></code> to set up a synchronous <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> request to <code><span style="font-size:10pt;font-family:&quot;">index.html</span></code>:</p>
<pre>1 var req = new XMLHttpRequest();
2 req.open(’GET’, ’index.html’, false);
3 req.send(null);
4 if(req.status == 200)
5 alert(req.responseText);</pre>
<h3>2.1.2 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest::Send()</span></code></h3>
<p>The<code><span style="font-size:10pt;font-family:&quot;"> send</span></code> method makes the connection to the URL specified in <code><span style="font-size:10pt;font-family:&quot;">open</span></code>.<br />
If the request is asynchronous, the call will return it immediately;<br />
otherwise, the call will block further execution until the page has<br />
been downloaded. If the request type is <code><span style="font-size:10pt;font-family:&quot;">POST</span></code>, the payload will be sent as the body of the request that is sent to the server. The method signature is:</p>
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
<p>send(payload)&lt;br /&gt; </p>
<p>When you make a <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> request, you will need to set the <code><span style="font-size:10pt;font-family:&quot;">Content-type</span></code> header. This way, the server knows what to do with the uploaded content. To mimic sending a form using HTTP <code><span style="font-size:10pt;font-family:&quot;">POST</span></code>, you set the content type to <code><span style="font-size:10pt;font-family:&quot;">application/x-www-form-urlencoded</span></code>. <code><span style="font-size:10pt;font-family:&quot;">URLencoded</span></code><br />
data is the same format that you see in a URL after the “?”. You can<br />
see an example of this encoded data by making a form and setting its<br />
method to <code><span style="font-size:10pt;font-family:&quot;">GET</span></code>. The following example shows a synchronous <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> request to <code><span style="font-size:10pt;font-family:&quot;">index.php</span></code> that is sending a <code><span style="font-size:10pt;font-family:&quot;">URLencoded</span></code> payload. If <code><span style="font-size:10pt;font-family:&quot;">index.php</span></code> contains <code><span style="font-size:10pt;font-family:&quot;">&lt;?php var_dump($_POST); ?&gt;</span></code>, you can see the submitted data translated as if it’s a normal form in the alert:</p>
<table style="width:429pt;" border="0" cellspacing="0" cellpadding="0" width="572">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> req = <span class="keyword">new</span> XMLHttpRequest();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.open(’POST’, ’index.php’, <span class="keyword">false</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.setRequestHeader(’Content-type’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’application/x-www-form-urlencoded;charset=UTF-8;’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.send(’hello=world&amp;XMLHttpRequest=test’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span>(req.status == 200)</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(req.responseText);</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
</tr>
</thead>
</table>
<p>var req = new XMLHttpRequest();&lt;br /&gt; req.open(’POST’, ’index.php’, false);&lt;br /&gt; req.setRequestHeader(’Content-type’,&lt;br /&gt; ’application/x-www-form-urlencoded;charset=UTF-8;’);&lt;br /&gt; req.send(’hello=world&amp;XMLHttpRequest=test’);&lt;br /&gt; if(req.status == 200)&lt;br /&gt; alert(req.responseText);&lt;br /&gt; </p>
<h3>2.1.3 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest::setRequestHeader()</span></code></h3>
<p>There are many different cases in which setting a header on a request might be useful. The most common use of <code><span style="font-size:10pt;font-family:&quot;">setRequestHeader()</span></code> is to set the <code><span style="font-size:10pt;font-family:&quot;">Content-type</span></code>, because most Web applications already know how to deal with certain types, such as <code><span style="font-size:10pt;font-family:&quot;">URLencoded</span></code>. The <code><span style="font-size:10pt;font-family:&quot;">setRequestHeader</span></code> method signature takes two parameters: the header to set and its value:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">setRequestHeader(header,value)</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
</tr>
</thead>
</table>
<p>setRequestHeader(header,value)&lt;br /&gt; </p>
<p>Because requests sent using <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> send the<br />
same standard headers, including cookie headers and HTTP authentication<br />
headers, as a normal browser request, the header name will usually be<br />
the name of the HTTP header that you want to override. In addition to<br />
overriding default headers, <code><span style="font-size:10pt;font-family:&quot;">setRequestHeader</span></code> is useful for setting custom, application-specific headers. Custom headers are generally prefixed with <code><span style="font-size:10pt;font-family:&quot;">X-</span></code> to distinguish them from standard ones. The following example makes a synchronous <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> request adding a header called <code><span style="font-size:10pt;font-family:&quot;">X-foo </span></code>to <code><span style="font-size:10pt;font-family:&quot;">test.php</span></code>. If <code><span style="font-size:10pt;font-family:&quot;">test.php</span></code> contains <code><span style="font-size:10pt;font-family:&quot;">&lt;?php var_dump($_SERVER); ?&gt;</span></code>, you will see the submitted header in the alert:</p>
<table style="width:4.75in;" border="0" cellspacing="0" cellpadding="0" width="456">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> req = <span class="keyword">new</span> XMLHttpRequest();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.open(’GET’, ’test.php’, <span class="keyword">false</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.setRequestHeader(’X-foo’,’bar’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.send(<span class="keyword">null</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span>(req.status == 200)</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(req.responseText);</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
</tr>
</thead>
</table>
<p>var req = new XMLHttpRequest();&lt;br /&gt; req.open(’GET’, ’test.php’, false);&lt;br /&gt; req.setRequestHeader(’X-foo’,’bar’);&lt;br /&gt; req.send(null);&lt;/p&gt; &lt;p&gt;if(req.status == 200)&lt;br /&gt; alert(req.responseText);&lt;br /&gt; </p>
<h3>2.1.4 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest::getResponseHeader()</span></code> and <code><span style="font-size:10pt;font-family:&quot;">getAllResponseHeaders()</span></code></h3>
<p>The <code><span style="font-size:10pt;font-family:&quot;">getResponseHeader</span></code> method allows you to get a single header from the response; this is especially useful when all you need is a header like <code><span style="font-size:10pt;font-family:&quot;">Content-type</span></code>; note that the specified header is case-insensitive. The method signature is as follows:</p>
<table style="width:201pt;" border="0" cellspacing="0" cellpadding="0" width="268">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">getResponseHeader(header)</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
</thead>
</table>
<p>getResponseHeader(header)&lt;br /&gt; </p>
<p><code><span style="font-size:10pt;font-family:&quot;">getAllResponseHeaders</span></code> returns all the headers from the<br />
response in a single string; this is useful for debugging or searching<br />
for a value. The following example makes a synchronous <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> request to <code><span style="font-size:10pt;font-family:&quot;">test.html</span></code>. When the client receives a response, the <code><span style="font-size:10pt;font-family:&quot;">Content-type</span></code> is alerted and all the headers are alerted:</p>
<table style="width:342.75pt;" border="0" cellspacing="0" cellpadding="0" width="457">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> req = <span class="keyword">new</span> XMLHttpRequest();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.open(’GET’, ’test.html’, <span class="keyword">false</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.send(<span class="keyword">null</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span>(req.status == 200) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(req.getResponseHeader(’Content-type’));</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(req.getAllResponseHeaders());</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">8</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
</tr>
</thead>
</table>
<p>var req = new XMLHttpRequest();&lt;br /&gt; req.open(’GET’, ’test.html’, false);&lt;br /&gt; req.send(null);&lt;/p&gt; &lt;p&gt;if(req.status == 200) {&lt;br /&gt; alert(req.getResponseHeader(’Content-type’));&lt;br /&gt; alert(req.getAllResponseHeaders());&lt;br /&gt; }&lt;br /&gt; </p>
<h3>2.1.5 Other <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> Methods</h3>
<p>All browsers implement an <code><span style="font-size:10pt;font-family:&quot;">abort()</span></code> method, which is<br />
used to cancel an in-progress asynchronous request. (An example of this<br />
is shown in the “Sending Asynchronous Requests” section in this<br />
chapter.) Mozilla-based browsers also offer some extra methods on top<br />
of the basic API; for instance, <code><span style="font-size:10pt;font-family:&quot;">addEventListener()</span></code> and <code><span style="font-size:10pt;font-family:&quot;">removeEventListener()</span></code> provide a way to catch status events without using the <code><span style="font-size:10pt;font-family:&quot;">on*</span></code> properties. There is also an <code><span style="font-size:10pt;font-family:&quot;">overrideMimeType()</span></code> method that makes it possible to force the <code><span style="font-size:10pt;font-family:&quot;">Content-type</span></code> to <code><span style="font-size:10pt;font-family:&quot;">text/xml</span></code><br />
so that it will be parsed into a DOM document even if the server<br />
doesn’t report it as such. The Mozilla-specific methods can be useful<br />
in certain circumstances, but in most cases, you should stay away from<br />
them because not all browsers support them.</p>
<h3>2.1.6 <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> Properties</h3>
<p><code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> provides a number of properties that<br />
provide information or results about the request. Most of the<br />
properties are self-explanatory; you simply read the value and act on<br />
it. The <code><span style="font-size:10pt;font-family:&quot;">on</span></code>* properties are event handlers that are used by assigning a function to them. A list of all the properties follows:</p>
<div>
<table style="width:75%;" border="0" cellpadding="0" width="75%">
<tbody>
<tr>
<td style="padding:.75pt;">
<ul type="disc">
<li class="MsoNormal"><strong><span>status</span></strong>.        The HTTP status code of the request response.</li>
<li class="MsoNormal"><strong><span>statusText</span></strong>.        The HTTP status code that goes with the code.</li>
<li class="MsoNormal"><strong><span>readyState</span></strong>.        The state of the request. (See Table 2-1 in the next section of this        chapter for values.)</li>
<li class="MsoNormal"><strong><span>responseText</span></strong>.        Unparsed text of the response.</li>
<li class="MsoNormal"><strong><span>responseXML</span></strong>.        Response parsed into a DOM Document object; happens only if Content-type        is <code><span style="font-size:10pt;font-family:&quot;">text/xml</span></code>.</li>
<li class="MsoNormal"><strong><span>onreadystatechange</span></strong>.        Event handler that is called when <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> changes.</li>
<li class="MsoNormal"><strong><span>onerror</span></strong>.        Mozilla-only event handler that is called when an error happens during a        request.</li>
<li class="MsoNormal"><strong><span>onprogress</span></strong>.        Mozilla-only event handler that is called at an interval as content is        loaded.</li>
<li class="MsoNormal"><strong><span>onload</span></strong>.        Mozilla-only event handler that is called when the document is finished        loading.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoTitle"><strong><span>NOTE</span></strong></p>
<p>Mozilla resets event handlers, such as <code><span style="font-size:10pt;font-family:&quot;">onreadystatechange</span></code>, after a request is completed, so you need to reset them if you are making multiple calls with the same object.</p>
<h3>2.1.7 <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> Reference</h3>
<p>Table 2-1 shows the possible values for the <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> variable. It will return a number representing the current state of the object. Each request will progress through the list of <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code>s.</p>
<h4><strong><span>Table 2-1 </span></strong><code><span style="font-size:10pt;font-family:&quot;">readyState</span></code><strong><span> Levels</span></strong></h4>
<table style="border:1.5pt outset;" border="1" cellpadding="0">
<tbody>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><strong><span style="font-size:10pt;font-family:&quot;">readyState </span></strong></code><strong><span>Status   Code</span></strong></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal"><strong><span>Status   of the</span></strong><code><strong><span style="font-size:10pt;font-family:&quot;"> XMLHttpRequest</span></strong></code><strong><span> Object</span></strong></p>
</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">(0)   UNINITIALIZED</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">The object has been created but not initialized. (The <code><span style="font-size:10pt;font-family:&quot;">open</span></code> method   has not been called.)</p>
</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">(1)   LOADING</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">The object has been created, but the <code><span style="font-size:10pt;font-family:&quot;">send</span></code> method   has not been called.</p>
</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">(2)   LOADED</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">The <code><span style="font-size:10pt;font-family:&quot;">send</span></code> method has been called, but the status and headers are not yet available.</p>
</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">(3)   INTERACTIVE</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Some data has been received. Calling the <code><span style="font-size:10pt;font-family:&quot;">responseBody</span></code> and <code><span style="font-size:10pt;font-family:&quot;">responseText</span></code><br />
properties at this state to obtain partial results will return an<br />
error, because status and response headers are not fully available.</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">(4)   COMPLETED</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">All the data has been received, and the complete data is   available in the <code><span style="font-size:10pt;font-family:&quot;">responseBody</span></code> and <code><span style="font-size:10pt;font-family:&quot;">responseText</span></code> properties.</p>
</td>
</tr>
</tbody>
</table>
<p>The <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> variable and the <code><span style="font-size:10pt;font-family:&quot;">onreadystatechange</span></code> event handler are linked in such a way that each time the <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> variable is changed, the <code><span style="font-size:10pt;font-family:&quot;">onreadystatechange</span></code> event handler is called.</p>
<h2>2.2 Cross-Browser <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code></h2>
<p>One of the attributes that have made <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
such a popular transport for Ajax requests is that it is easy to use in<br />
a way that is compatible across multiple browsers. The big two<br />
browsers, IE and Firefox, provide the same basic API. This consistency<br />
makes for a similar development experience. Opera and Safari also<br />
support the same basic API, but only in their more recent versions.</p>
<p>When you are writing cross-browser, the first problem you need to overcome is that <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
is an ActiveX object in IE, and it’s a normal JavaScript object in<br />
Mozilla and the other browsers. There are a number of approaches to<br />
overcoming this problem, including optional JScript code for IE, but I<br />
find that the simplest solution is just to use exceptions. Listing 2-1<br />
shows an example that tries every version of the <code><span style="font-size:10pt;font-family:&quot;">XMLHTTP</span></code><br />
ActiveX object, if needed. This helps make our implementation as robust<br />
as possible. The function also throws an exception if it’s not possible<br />
to create an <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> object. This gives us a way to give error messages or to fall back to <code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code> requests, if needed.</p>
<h4>Listing 2-1 <em>Cross-Browser </em><code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><em> Creation</em></h4>
<table style="width:457.5pt;" border="0" cellspacing="0" cellpadding="0" width="610">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// function to create an XMLHttpClient in a cross-browser manner</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">function</span> initXMLHttpClient() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> xmlhttp;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">try</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// Mozilla / Safari / IE7</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">xmlhttp = <span class="keyword">new</span> XMLHttpRequest();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">catch</span> (e) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">8</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// IE</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">9</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> XMLHTTP_IDS = <span class="keyword">new</span> Array(’MSXML2.XMLHTTP.5.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">10</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’MSXML2.XMLHTTP.4.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">11</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’MSXML2.XMLHTTP.3.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">12</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’MSXML2.XMLHTTP’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">13</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’Microsoft.XMLHTTP’ );</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">14</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> success = <span class="keyword">false</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">15</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">for</span> (<span class="keyword">var</span> i=0;i &lt; XMLHTTP_IDS.length &amp;&amp; !success; i++) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">16</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">try</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">17</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">xmlhttp = <span class="keyword">new</span> ActiveXObject(XMLHTTP_IDS[i]);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">18</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">success = <span class="keyword">true</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">19</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">catch</span> (e) {}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">20</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">21</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (!success) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">22</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">throw</span> <span class="keyword">new</span> Error(’Unable to create XMLHttpRequest.’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">23</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">24</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">25</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">return</span> xmlhttp;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">26</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
</thead>
</table>
<p>// function to create an XMLHttpClient in a cross-browser manner&lt;br /&gt; function initXMLHttpClient() {&lt;br /&gt; var xmlhttp;&lt;br /&gt; try {&lt;br /&gt; // Mozilla / Safari / IE7&lt;br /&gt; xmlhttp = new XMLHttpRequest();&lt;br /&gt; } catch (e) {&lt;br /&gt; // IE&lt;br /&gt; var XMLHTTP_IDS = new Array(’MSXML2.XMLHTTP.5.0’,&lt;br /&gt; ’MSXML2.XMLHTTP.4.0’,&lt;br /&gt; ’MSXML2.XMLHTTP.3.0’,&lt;br /&gt; ’MSXML2.XMLHTTP’,&lt;br /&gt; ’Microsoft.XMLHTTP’ );&lt;br /&gt; var success = false;&lt;br /&gt; for (var i=0;i &lt; XMLHTTP_IDS.length &amp;&amp; !success; i++) {&lt;br /&gt; try {&lt;br /&gt; xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);&lt;br /&gt; success = true;&lt;br /&gt; } catch (e) {}&lt;br /&gt; }&lt;br /&gt; if (!success) {&lt;br /&gt; throw new Error(’Unable to create XMLHttpRequest.’);&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; return xmlhttp;&lt;br /&gt; }&lt;br /&gt; </p>
<p>The overall pattern of this code is simple: Create an <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
instance in the most optimal way possible, as shown in line 6. This<br />
creation should always succeed on Mozilla-based browsers, such as<br />
Firefox, on Opera, and on the upcoming IE 7.</p>
<p>If <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> doesn’t exist, catch the exception<br />
that is thrown, as shown in line 7. Getting an exception means you’re<br />
on IE or an old browser. To test for IE, attempt to create an ActiveX<br />
version of <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>, which is accomplished by the following:</p>
<ol type="1">
<li class="MsoNormal">Looping over all possible      ActiveX identifiers. This action will<br />
create an ActiveX instance for each identifier until the creation<br />
succeeds, setting the success flag to <code><span style="font-size:10pt;font-family:&quot;">true</span></code>, as shown in lines 9–20.</li>
<li class="MsoNormal">If creation is successful,      returning an<code><span style="font-size:10pt;font-family:&quot;"> XMLHttpRequest</span></code> instance, as shown in line 25. Otherwise,      throwing a JavaScript exception, as shown in line 22.</li>
</ol>
<p>This approach allows for minimal overhead if the browser supports a native <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> object while fully supporting IE. It also gives us an error if <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
isn’t supported at all. This error could be displayed to the user at<br />
this point, or you could insert another communication approach, such as<br />
hidden <code><span style="font-size:10pt;font-family:&quot;">IFrames</span></code>.</p>
<h2>2.3 Sending Asynchronous Requests</h2>
<p>Synchronous requests are easier to use than asynchronous requests<br />
because they return data directly and remove the hassle of creating<br />
callback functions. However, they aren’t the standard use case for <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
because the entire browser is locked while the request is happening.<br />
There are some circumstances in which blocking is useful (mainly when a<br />
decision needs to be made before the current function ends), but in<br />
most cases, you’ll want these requests to happen in the background. An<br />
asynchronous request allows the browser to continue running JavaScript<br />
code and users to continue interacting with the page while the new data<br />
is loaded. With the proper user interface, asynchronous communication<br />
allows an Ajax application to be useful even when the user’s connection<br />
to the site is slow.</p>
<p>To make an asynchronous call, we need to accomplish two tasks: set the asynchronous flag on open to <code><span style="font-size:10pt;font-family:&quot;">true</span></code>, and add a <code><span style="font-size:10pt;font-family:&quot;">readyStateChanged</span></code><br />
event handler. This event handler will wait for a ready state of 4,<br />
which means the response is loaded. It will then check the status<br />
property. If the status is 200, we can use<code><span style="font-size:10pt;font-family:&quot;"> responseText</span></code>; if it’s another value, we have an error, so we’ll need to create an alert dialog to show it. An asynchronous call to <code><span style="font-size:10pt;font-family:&quot;">test.php</span></code> is shown in Listing 2-2. The <code><span style="font-size:10pt;font-family:&quot;">initXMLHttpClient</span></code> function from an earlier chapter section, “Cross-Browser <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>,” is used to create our <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> object.</p>
<h4>Listing 2-2 Making an Asynchronous Request</h4>
<table style="width:406.5pt;" border="0" cellspacing="0" cellpadding="0" width="542">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> req = initXMLHttpClient();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.onreadystatechange = <span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (req.readyState == 4) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (req.status == 200) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(req.responseText);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">else</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(’Loading Error: [’+req.status+’] ’</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">8</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">+req.statusText);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">9</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">10</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">11</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">12</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.open(’GET’,’test.php’,<span class="keyword">true</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">13</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">req.send(<span class="keyword">null</span>);</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
</thead>
</table>
<p>var req = initXMLHttpClient();&lt;br /&gt; req.onreadystatechange = function() {&lt;br /&gt; if (req.readyState == 4) {&lt;br /&gt; if (req.status == 200) {&lt;br /&gt; alert(req.responseText);&lt;br /&gt; } else {&lt;br /&gt; alert(’Loading Error: [’+req.status+’] ’&lt;br /&gt; +req.statusText);&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; req.open(’GET’,’test.php’,true);&lt;br /&gt; req.send(null);&lt;br /&gt; </p>
<p>Although this code gets the job done, it’s not a great long-term solution because we will have to write a new <code><span style="font-size:10pt;font-family:&quot;">onreadystatechange</span></code> method for each call. The solution to this is to create our own <code><span style="font-size:10pt;font-family:&quot;">HttpClient</span></code> class that wraps <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>.<br />
Such a class gives us an easy-to-use API and a property to use for the<br />
callback that has to deal only with successful requests. Just adding<br />
some helper methods would be a simpler solution, but that’s not a<br />
possibility because IE doesn’t allow you to add methods to an ActiveX<br />
object.</p>
<p>A sample <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest wrapper</span></code> class is shown in Listing 2-3. The main features of the <code><span style="font-size:10pt;font-family:&quot;">HttpClient</span></code> class are a <code><span style="font-size:10pt;font-family:&quot;">callback</span></code> property that is called when a successful asynchronous request is complete and a <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code> method that combines the <code><span style="font-size:10pt;font-family:&quot;">open</span></code> and <code><span style="font-size:10pt;font-family:&quot;">send</span></code> functions. It also provides event properties that are called when a request is made (<code><span style="font-size:10pt;font-family:&quot;">onSend</span></code>), when it ends (<code><span style="font-size:10pt;font-family:&quot;">onload</span></code>), and when an errors occurs (<code><span style="font-size:10pt;font-family:&quot;">onError</span></code>). A default <code><span style="font-size:10pt;font-family:&quot;">onSend</span></code> and <code><span style="font-size:10pt;font-family:&quot;">onLoad</span></code> implementation is provided, which creates a basic loading message while requests are being made.</p>
<h4><strong><span>Listing 2-3 </span></strong><code><span style="font-size:10pt;font-family:&quot;">HttpClient XMLHttpRequest</span></code><em> Wrapper</em></h4>
<table style="width:471pt;" border="0" cellspacing="0" cellpadding="0" width="628">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">function</span> HttpClient() { }</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">HttpClient.prototype = {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// type GET,POST passed to open</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">requestType:’GET’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// when set to true, async calls are made</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">isAsync:<span class="keyword">false</span>,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">8</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// where an XMLHttpRequest instance is stored</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">9</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">xmlhttp:<span class="keyword">false</span>,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">10</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">11</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// what is called when a successful async call is made</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">12</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">callback:<span class="keyword">false</span>,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">13</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">14</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// what is called when send is called on XMLHttpRequest</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">15</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// set your own function to onSend to have a custom loading</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">16</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// effect</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">17</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">onSend:<span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">18</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">document.getElementById(’HttpClientStatus’).style.display =</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">19</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’block’;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">20</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">},</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">21</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">22</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// what is called when readyState 4 is reached, this is</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">23</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// called before your callback</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">24</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">onload:<span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">25</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">document.getElementById(’HttpClientStatus’).style.display =</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">26</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’none’;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">27</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">},</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">28</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">29</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// what is called when an http error happens</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">30</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">onError:<span class="keyword">function</span>(error) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">31</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">alert(error);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">32</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">},</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">33</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">34</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// method to initialize an xmlhttpclient</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">35</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">init:<span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">36</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">try</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">37</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// Mozilla / Safari</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">38</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.xmlhttp = <span class="keyword">new</span> XMLHttpRequest();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">39</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">catch</span> (e) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">40</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// IE</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">41</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> XMLHTTP_IDS = <span class="keyword">new</span> Array(-’MSXML2.XMLHTTP.5.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">42</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-’MSXML2.XMLHTTP.4.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">43</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’MSXML2.XMLHTTP.3.0’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">44</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">’MSXML2.XMLHTTP’,</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">45</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-’Microsoft.XMLHTTP’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">46</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> success = <span class="keyword">false</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">47</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="keyword">for</span> (<span class="keyword">var</span> i=0;i &lt; XMLHTTP_IDS.length &amp;&amp; !success; i++) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">48</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">try</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">49</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="keyword">this</span>.xmlhttp = <span class="keyword">new</span> ActiveXObject(XMLHTTP_IDS[i]);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">50</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">success = <span class="keyword">true</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">51</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">catch</span> (e) {}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">52</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">53</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="keyword">if</span> (!success) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">54</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="keyword">this</span>.onError(’Unable to create XMLHttpRequest.’);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">55</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">56</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">57</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">},</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">58</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">59</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// method to make a page request</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">60</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// @param string url The page to make the request to</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">61</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// @param string payload What you’re sending if this is a POST</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">62</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">//            request</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">63</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">makeRequest: <span class="keyword">function</span>(url,payload) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">64</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (!<span class="keyword">this</span>.xmlhttp) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">65</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.init();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">66</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">67</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.xmlhttp.open(<span class="keyword">this</span>.requestType,url,<span class="keyword">this</span>.isAsync);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">68</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">69</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="comment">// set onreadystatechange here since it will be reset after a</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">70</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">//completed call in Mozilla</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">71</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> self = <span class="keyword">this</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">72</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.xmlhttp.onreadystatechange = <span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">73</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">self._readyStateChangeCallback(); }</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">74</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">75</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.xmlhttp.send(payload);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">76</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">77</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (!<span class="keyword">this</span>.isAsync) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">78</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">return</span> <span class="keyword">this</span>.xmlhttp.responseText;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">79</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">80</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">},</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">81</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">82</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="comment">// internal method used to handle ready state changes</span></p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">83</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">_readyStateChangeCallback:<span class="keyword">function</span>() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">84</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">switch</span>(<span class="keyword">this</span>.xmlhttp.readyState) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">85</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">case</span> 2:</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">86</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.onSend();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">87</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">break</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">88</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">case</span> 4:</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">89</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.onload();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">90</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">if</span> (<span class="keyword">this</span>.xmlhttp.status == 200) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">91</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">this</span>.callback(<span class="keyword">this</span>.xmlhttp.responseText);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">92</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">} <span class="keyword">else</span> {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">93</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-<span class="keyword">this</span>.onError(’HTTP Error Making Request: ’+</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">94</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-’[’+<span class="keyword">this</span>.xmlhttp.status+’]’+</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">95</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">-’+<span class="keyword">this</span>.xmlhttp.statusText));</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">96</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">97</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">break</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">98</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">99</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">100</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
</td>
</tr>
</thead>
</table>
<p>function HttpClient() { }&lt;br /&gt; HttpClient.prototype = {&lt;br /&gt; // type GET,POST passed to open&lt;br /&gt; requestType:’GET’,&lt;br /&gt; // when set to true, async calls are made&lt;br /&gt; isAsync:false,&lt;/p&gt; &lt;p&gt; // where an XMLHttpRequest instance is stored&lt;br /&gt; xmlhttp:false,&lt;/p&gt; &lt;p&gt; // what is called when a successful async call is made&lt;br /&gt; callback:false,&lt;/p&gt; &lt;p&gt; // what is called when send is called on XMLHttpRequest&lt;br /&gt; // set your own function to onSend to have a custom loading&lt;br /&gt; // effect&lt;br /&gt; onSend:function() {&lt;br /&gt; document.getElementById(’HttpClientStatus’).style.display =&lt;br /&gt; ’block’;&lt;br /&gt; },&lt;/p&gt; &lt;p&gt; // what is called when readyState 4 is reached, this is&lt;br /&gt; // called before your callback&lt;br /&gt; onload:function() {&lt;br /&gt; document.getElementById(’HttpClientStatus’).style.display =&lt;br /&gt; ’none’;&lt;br /&gt; },&lt;/p&gt; &lt;p&gt; // what is called when an http error happens&lt;br /&gt; onError:function(error) {&lt;br /&gt; alert(error);&lt;br /&gt; },&lt;/p&gt; &lt;p&gt; // method to initialize an xmlhttpclient&lt;br /&gt; init:function() {&lt;br /&gt; try {&lt;br /&gt; // Mozilla / Safari&lt;br /&gt; this.xmlhttp = new XMLHttpRequest();&lt;br /&gt; } catch (e) {&lt;br /&gt; // IE&lt;br /&gt; var XMLHTTP_IDS = new Array(-’MSXML2.XMLHTTP.5.0’,&lt;br /&gt; -’MSXML2.XMLHTTP.4.0’,&lt;br /&gt; ’MSXML2.XMLHTTP.3.0’,&lt;br /&gt; ’MSXML2.XMLHTTP’,&lt;br /&gt; -’Microsoft.XMLHTTP’);&lt;br /&gt; var success = false;&lt;br /&gt; -for (var i=0;i &lt; XMLHTTP_IDS.length &amp;&amp; !success; i++) {&lt;br /&gt; try {&lt;br /&gt; -this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);&lt;br /&gt; success = true;&lt;br /&gt; } catch (e) {}&lt;br /&gt; -}&lt;br /&gt; -if (!success) {&lt;br /&gt; -this.onError(’Unable to create XMLHttpRequest.’);&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; },&lt;/p&gt; &lt;p&gt; // method to make a page request&lt;br /&gt; // @param string url The page to make the request to&lt;br /&gt; // @param string payload What you’re sending if this is a POST&lt;br /&gt; // request&lt;br /&gt; makeRequest: function(url,payload) {&lt;br /&gt; if (!this.xmlhttp) {&lt;br /&gt; this.init();&lt;br /&gt; }&lt;br /&gt; this.xmlhttp.open(this.requestType,url,this.isAsync);&lt;/p&gt; &lt;p&gt; -// set onreadystatechange here since it will be reset after a&lt;br /&gt; //completed call in Mozilla&lt;br /&gt; var self = this;&lt;br /&gt; this.xmlhttp.onreadystatechange = function() {&lt;br /&gt; self._readyStateChangeCallback(); }&lt;/p&gt; &lt;p&gt; this.xmlhttp.send(payload);&lt;/p&gt; &lt;p&gt; if (!this.isAsync) {&lt;br /&gt; return this.xmlhttp.responseText;&lt;br /&gt; }&lt;br /&gt; },&lt;/p&gt; &lt;p&gt;// internal method used to handle ready state changes&lt;br /&gt; _readyStateChangeCallback:function() {&lt;br /&gt; switch(this.xmlhttp.readyState) {&lt;br /&gt; case 2:&lt;br /&gt; this.onSend();&lt;br /&gt; break;&lt;br /&gt; case 4:&lt;br /&gt; this.onload();&lt;br /&gt; if (this.xmlhttp.status == 200) {&lt;br /&gt; this.callback(this.xmlhttp.responseText);&lt;br /&gt; } else {&lt;br /&gt; -this.onError(’HTTP Error Making Request: ’+&lt;br /&gt; -’[’+this.xmlhttp.status+’]’+&lt;br /&gt; -’+this.xmlhttp.statusText));&lt;br /&gt; }&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; </p>
<p>The <code><span style="font-size:10pt;font-family:&quot;">HttpClient</span></code> class contains comments explaining its<br />
basic functionality, but you will want to look at a couple of areas in<br />
detail. The first areas are the properties you’ll want to set while<br />
interacting with the class; these include the following:</p>
<ul type="disc">
<li class="MsoNormal"><strong><span>requestType (line 4).</span></strong> Used to set the HTTP request type, <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> is used to request content      that doesn’t perform an action whereas <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> is used for requests that      do.</li>
<li class="MsoNormal"><strong><span>isAsync (line 6).</span></strong> A<br />
Boolean value used to set the request method. The default is false,<br />
which makes an synchronous request. If you’re making an asynchronous<br />
request, <code><span style="font-size:10pt;font-family:&quot;">isAsync</span></code> is set to <code><span style="font-size:10pt;font-family:&quot;">true</span></code>.      When making an asynchronous request, you also need to set the <code><span style="font-size:10pt;font-family:&quot;">callback</span></code> property.</li>
<li class="MsoNormal"><strong><span>callback (line 12)</span></strong>.      This property takes a function that takes a single parameter result and is      called when a request is successfully completed.</li>
</ul>
<p>Lines 16–31 contain simple functions for handling some basic user<br />
feedback. When a request is sent to the server, a DOM element with the<br />
ID of <code><span style="font-size:10pt;font-family:&quot;">HttpClientStatus</span></code><br />
is shown (lines 16–19). When it completes, it is hidden again (lines<br />
23–26). The class also defines a function to call when an error happens<br />
(lines 29–31); it creates an alert box with the error message. Common<br />
errors include receiving a <code><span style="font-size:10pt;font-family:&quot;">404 page not found</span></code> HTTP error message or not being able to create an <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
object. The implementation of these three functions is simple, and<br />
you’ll likely want to override them with more sophisticated<br />
application-specific versions.</p>
<p>Lines 33–56 contain the <code><span style="font-size:10pt;font-family:&quot;">init</span></code> method, which is identical to the <code><span style="font-size:10pt;font-family:&quot;">initXMLHttpClient</span></code> function we created in Listing 2-1, except for what it does with its error message. Now it sends it to the <code><span style="font-size:10pt;font-family:&quot;">onError</span></code> method. You won’t be dealing with this function directly because the <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code> method will take care of it for you. The <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code><br />
method (lines 62–79) is your main interaction with the class. It takes<br />
two parameters: a URL to which to make the request and a payload that<br />
is sent to the server if you’re making a <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> request. The actual implementation is a more generic version of the code shown in Listing 2-2. The _<code><span style="font-size:10pt;font-family:&quot;">readyStateChangeCallback</span></code> (lines 82–99) method is set as the <code><span style="font-size:10pt;font-family:&quot;">readyState</span></code> handler by <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code>. It handles calling <code><span style="font-size:10pt;font-family:&quot;">onSend</span></code> when the initial request is sent and then calling <code><span style="font-size:10pt;font-family:&quot;">onload</span></code> when the request completes. It also checks for a <code><span style="font-size:10pt;font-family:&quot;">200 HTTP</span></code> status code and calls <code><span style="font-size:10pt;font-family:&quot;">onError</span></code> if some other status is returned.</p>
<p>Listing 2-4 uses the <code><span style="font-size:10pt;font-family:&quot;">HttpClient</span></code> class and shows its<br />
basic usage. A wrapper class like this helps cut down the amount of<br />
code you need to write per request while giving a single place to make<br />
future changes.</p>
<h4>Listing 2-4 <em>Using the </em><code><span style="font-size:10pt;font-family:&quot;">HttpClient XMLHttpRequest</span></code><em> Wrapper</em></h4>
<table style="width:417.75pt;" border="0" cellspacing="0" cellpadding="0" width="557">
<tbody>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">1</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;html&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">2</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;head&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">3</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;title&gt;Simple XMLHttpRequest Wrapper Test Page&lt;/title&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">4</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">5</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;script type=<span class="string">“text/javascript”</span> src=<span class="string">“HttpClient.js”</span>&gt;&lt;/script&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">6</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;body&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">7</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;script type=<span class="string">“text/javascript”</span>&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">8</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">9</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">var</span> client = <span class="keyword">new</span> HttpClient();</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">10</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">client.isAsync = <span class="keyword">true</span>;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">11</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">12</p>
</td>
<td style="padding:0;">
<p class="MsoNormal"><span class="keyword">function</span> test() {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">13</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">client.callback = <span class="keyword">function</span>(result) {</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">14</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">document.getElementById(’target’).innerHTML = result;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">15</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">16</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">client.makeRequest(’.’,<span class="keyword">null</span>);</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">17</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">}</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">18</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;/script&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">19</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">20</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;div id=<span class="string">“HttpClientStatus”</span> style=<span class="string">“display:none”</span>&gt;Loading …&lt;/div&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">21</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;a href=’javascript:test()’&gt;Make an Async Test call&lt;/a&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">22</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;div id=<span class="string">“target”</span>&gt;&lt;/div&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">23</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;/body&gt;</p>
</td>
</tr>
<tr>
<td style="padding:0;">
<p class="MsoNormal">24</p>
</td>
<td style="padding:0;">
<p class="MsoNormal">&lt;/html&gt;</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td style="padding:0;">
<p class="MsoNormal">
</td>
<td style="padding:0;">
<p class="MsoNormal">
</td>
</tr>
</thead>
</table>
<p>&lt;html&gt;&lt;br /&gt; &lt;head&gt;&lt;br /&gt; &lt;title&gt;Simple XMLHttpRequest Wrapper Test Page&lt;/title&gt;&lt;/p&gt; &lt;p&gt;&lt;mce:script type=”text/javascript” src=”HttpClient.js” mce_src=”HttpClient.js”&gt;&lt;/mce:script&gt;&lt;br /&gt; &lt;body&gt;&lt;br /&gt; &lt;mce:script type=”text/javascript”&gt;&lt;!– &lt;/p&gt; &lt;p&gt;var client = new HttpClient();&lt;br /&gt; client.isAsync = true;&lt;/p&gt; &lt;p&gt;function test() {&lt;br /&gt; client.callback = function(result) {&lt;br /&gt; document.getElementById(’target’).innerHTML = result;&lt;br /&gt; }&lt;br /&gt; client.makeRequest(’.’,null);&lt;br /&gt; }&lt;br /&gt; // –&gt;&lt;/mce:script&gt;&lt;/p&gt; &lt;p&gt;&lt;div id=”HttpClientStatus” style=”display:none” mce_style=”display:none”&gt;Loading …&lt;/div&gt;&lt;br /&gt; &lt;a href=”’javascript:test()’” mce_href=”’javascript:test()’”&gt;Make an Async Test call&lt;/a&gt;&lt;br /&gt; &lt;div id=”target”&gt;&lt;/div&gt;&lt;br /&gt; &lt;/body&gt;&lt;br /&gt; &lt;/html&gt;&lt;br /&gt; </p>
<p>Using the <code><span style="font-size:10pt;font-family:&quot;">HttpClient XMLHttpRequest</span></code> wrapper is a<br />
simple task. You start by including it in the header of your HTML page<br />
(line 5), and then you can proceed to use it. You do this by creating<br />
an instance of the class (line 9), configuring its basic properties (in<br />
this case, setting <code><span style="font-size:10pt;font-family:&quot;">isAsync</span></code> to true (line 10)), and then setting up some code to call <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code>.<br />
In most cases, this code will be contained in a function so that it can<br />
be tied to a user-driven event, such as clicking a link. The call is<br />
made by the <code><span style="font-size:10pt;font-family:&quot;">test</span></code> function (lines 12–17); the <code><span style="font-size:10pt;font-family:&quot;">test</span></code> function first sets up a callback to run when the request is complete (lines 13–15), and then it calls <code><span style="font-size:10pt;font-family:&quot;">makeRequest</span></code> (line 16), which starts the Ajax call.</p>
<h2>2.4 Ajax Without <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code></h2>
<p>There are a number of cases in which you might not have <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code><br />
support. The most common would be in the case of an older browser. This<br />
is the hardest to work around, not because there is no Ajax fallback,<br />
but because all the other DOM manipulation that you do within the<br />
application won’t work. Another problem case is when your browser<br />
supports everything that is needed except for <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>. This problem could occur when IE is in a mode where it can’t use <code><span style="font-size:10pt;font-family:&quot;">ActiveXObjects</span></code><br />
or when you are using a pre-7.6 version of Opera. In some cases,<br />
especially intranet applications, it’s easy to just require an upgrade,<br />
but if you want to use Ajax on a public site, you’ll want to think<br />
about using some sort of fallback mechanism. The best candidate for a<br />
fallback is to use hidden <code><span style="font-size:10pt;font-family:&quot;">IFrames</span></code>. Another option is to<br />
use cookies, but they can send only a limited amount of data per<br />
request, so it is hard to drop in cookie-based approaches as a<br />
replacement for code that has been written with <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> in mind. Only <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> supports synchronous calls, so if they are necessary for your application, then using it as a fallback will not be possible.</p>
<p>If you’re using a fully wrapped <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> and<br />
you don’t use synchronous calls, providing transparent fallback to your<br />
program should be possible. You need only to replace the final throwing<br />
of an exception in the example <code><span style="font-size:10pt;font-family:&quot;">init</span></code> method with the instantiation of your <code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code> HTTP client. The main item to remember about using another approach instead of <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code> is that it’s not going to gain you huge leaps in compatibility. The major browsers already support <code><span style="font-size:10pt;font-family:&quot;">XMLHttpRequest</span></code>.<br />
This support makes browsers with JavaScript turned off, not those<br />
running an unsupported browser, the biggest group that can’t use your<br />
Ajax application. The advantages and disadvantages of the Ajax<br />
communication techniques are shown in Table 2-2.</p>
<h4><strong><span>Table 2-2 Advantages and Disadvantages of Ajax Techniques</span></strong></h4>
<table style="border:1.5pt outset;" border="1" cellpadding="0">
<tbody>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><strong><span>Technique</span></strong></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal"><strong><span>Advantages</span></strong></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal"><strong><span>Disadvantages</span></strong></p>
</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">XMLHttpReques</span></code>t</p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Can make requests to pages not set up for Ajax</p>
<p>Can set/get all HTTP headers</p>
<p>Can make HTTP requests using any type (<code><span style="font-size:10pt;font-family:&quot;">GET</span></code>, <code><span style="font-size:10pt;font-family:&quot;">POST</span></code>, <code><span style="font-size:10pt;font-family:&quot;">PROPFIND</span></code>,   and so on)</p>
<p>Supports full control over <code><span style="font-size:10pt;font-family:&quot;">POST </span></code>requests, allowing for any type of data   encoding</p>
<p>Requests ActiveX to be enabled in IE 5 and 6</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Is only available in newer versions of Opera and   Safari</p>
<p>Has small implementation differences between browsers</td>
</tr>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code></p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Can make <code><span style="font-size:10pt;font-family:&quot;">POST</span></code> and <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> HTTP requests</p>
<p>Supportes all modern browsers</p>
<p>Supports asynchronous file uploads</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Prohibits synchronous requests</p>
<p>Server pages must be designed to work with <code><span style="font-size:10pt;font-family:&quot;">IFrame</span></code> requests</p>
<p>Has implementation differences between browsers</p>
<p>Can leave extra entries in browser history (depends on browser and   implementation)</p>
<p>All request data is URL-encoded, increasing request size</td>
</tr>
</tbody>
</table>
<p><span style="font-size:12pt;font-family:&quot;"><br /> </span></p>
<p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--></p>
<table style="border:1.5pt outset;" border="1" cellpadding="0">
<tbody>
<tr>
<td style="padding:1.5pt;">
<p class="MsoNormal">Cookies</p>
</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Supports the largest number of browsers</p>
<p>Few implementation differences between browsers</p>
<p>Prohibits no synchronous requests</td>
<td style="padding:1.5pt;">
<p class="MsoNormal">Doesn’t work with large requests/results</p>
<p>Requires server pages to be designed to work with cookie requests</p>
<p>Requires polling on the client</p>
<p>Can make only <code><span style="font-size:10pt;font-family:&quot;">GET</span></code> HTTP requests</td>
</tr>
</tbody>
</table>
<h3><!--[if !supportEmptyParas]--> <!--[endif]--></h3>
<p>Posted by: <a href="http://www.expertzweb.com">Expertz Web</a></p>
<br />Posted in Latest News, Web Development Tagged: ajax, ajax development, ajax getting started, ajax overview, ajax programming, ajax start, overview of ajax, start ajax <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/expertzweb.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/expertzweb.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/expertzweb.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=expertzweb.wordpress.com&amp;blog=5042395&amp;post=50&amp;subd=expertzweb&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://expertzweb.wordpress.com/2008/10/08/getting-started-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2008a563e265ac0535bbfeffa4ba1b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Miracle Studois</media:title>
		</media:content>
	</item>
	</channel>
</rss>
