<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seifi.org &#187; ajax</title>
	<atom:link href="http://www.seifi.org/category/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://www.seifi.org</link>
	<description>A Web Development Blog by Joe Seifi - seifi.org</description>
	<lastBuildDate>Thu, 12 Aug 2010 05:35:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How Google Analytics determines Connection Speeds</title>
		<link>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html</link>
		<comments>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html#comments</comments>
		<pubDate>Wed, 12 Mar 2008 18:43:55 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stats]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/how-google-analytics-determines-connection-speeds.html</guid>
		<description><![CDATA[Today I was looking for an unobtrusive method of determining a user&#8217;s connection speed using JavaScript. A quick search on Google returned an array of tricks mostly having to do with using Ajax to make a call behind the scenes, and track the payload time for the small file. In most cases people use an [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was looking for an unobtrusive method of determining a user&#8217;s connection speed using JavaScript. A quick <a href="http://www.google.com/search?q=javascript+connection+speed" target="_blank">search</a> on Google returned an array of <a href="http://myspeed.ebiene.de/" target="_blank">tricks</a> mostly having to do with using Ajax to make a call behind the scenes, and track the payload time for the small file. In most cases people use an image with a random variable at the end to avoid caching, like image.jpg?foo=1Rt2X21. This is all good but adds an HTTP connection which could potentially interfere with the user&#8217;s experience, especially if they are already on a slow connection to begin with.<span id="more-627"></span></p>
<p>Then I discovered something interesting in <a href="https://www.google.com/analytics/" target="_blank">Google Analytics</a>.</p>
<p>Google Analytics tracks and stores connection speeds for your visitors as part of the Network Properties category. The data provided includes Connection Speed and this corresponds with Pages per visit, Average time on Site, Percentage of new visits, and the Bounce rate. But how in the world does Google compile this data? It <a href="http://groups.google.com/group/analytics-help-basics/browse_thread/thread/c3c01931dcdcf1d/07a492c88916f80e?lnk=gst&amp;q=speed#07a492c88916f80e" target="_blank">appears</a> that people are <a href="http://informationgift.com/2006/10/analytics_guesses_connection_s.html" target="_blank">guessing</a> that Google uses the visitor&#8217;s IP address or hostname to do a lookup in an IP database or a <a href="http://groups.google.com/group/analytics-help-tracking/browse_thread/thread/9206114c0909379e/078a201bc3e9b566?lnk=gst&amp;q=speed#078a201bc3e9b566" target="_blank">reverse lookup</a>, and then makes a guess based on what ISP that IP address belongs to. But Google also loads a small .gif file with each <a href="http://www.google.com/support/urchin45/bin/answer.py?answer=28307" target="_blank">urchin</a> request. This article explains a little trick for using time stamped image loading and <a href="http://www.die.net/musings/page_load_time/" target="_blank">log analysis</a> which seems related.</p>
<p><img src="http://www.seifi.org/wp-content/uploads/2008/03/analyticsconnectionspeeds.gif" alt="Google Analytics Connection Speeds" /></p>
<p>So if your IP belongs to RoadRunner, then we can assume you are on a cable connection and file you under that category. This can sometimes get somewhat hairy and lead to ambiguity as evidenced by the Unknown category shown in Google Analytics. It is also interesting to note the Unknown category is the single largest category in my case with 36% of the total data collected. What happens if you are on AOL or EarthLink? Will the database contain the accurate information to pinpoint if you are on dial-up or broadband? How often is the database updated with new information? What about edge cases, for example if you work in an office where you have a &#8220;broadband&#8221; connection but share it with a large group of people?</p>
<p>The good news is that with Analytics the work happens without interfering with the user experience and no additional HTTP connections are needed. The bad news is, it is not done in real time. So if you are looking for a real-time test this will not work for you, unless you build your own seriously fast IP database web service that you can use asynchronously. The other option is to use the binary image payload test, but that also makes life hard for your users.</p>
<p>So, If you are looking for general statistics for a webapp over a date range then Google Analytics might be the way to go. Keep in mind you will end up with a chunk of Unknown data. As for making snap decisions, you can sniff user bandwidth while they surf with payload testing. Here is another sample <a href="http://site.aol.com/speed.html" target="_blank">page at AOL</a> where they put up a simple fork page and determine your bandwidth speed using JavaScript image loading and setting a user cookie. I can think of a dozen reasons why this is a bad idea but I won&#8217;t go into that here.</p>
<p><!--Content type: SDKML. Transform: wc2mtps.xslt.-->PS. It is worth mentioning that Internet Explorer supports a built in behavior called clientCaps, which provides information about features supported by Microsoft Internet Explorer, as well as a way for installing browser components on demand. The <a href="http://msdn2.microsoft.com/en-us/library/ms531088(VS.85).aspx" target="_blank">connectionType</a> property of clientCaps returns either <strong>lan</strong>, <strong>modem </strong>or <strong>offline</strong>. Since this only works in IE and doesn&#8217;t offer too much granularity, it might be a good test if you are <em>only trying to test IE users specifically</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/how-google-analytics-determines-connection-speeds.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sniff and Disable Firebug Howto (Gmail example)</title>
		<link>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html</link>
		<comments>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html#comments</comments>
		<pubDate>Wed, 28 Nov 2007 20:02:38 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/sniff-and-disable-firebug-howto-gmail-example.html</guid>
		<description><![CDATA[Here is a simple test to see if users have Firebug installed on their browsers. Obviously this would also weed out non-FireFox users. if &#40;window.console &#38;&#38; window.console.firebug&#41; &#123; alert&#40;&#34;found Firebug&#34;&#41;; &#125;else&#123; alert&#40;&#34;can't find Firebug&#34;&#41;; &#125; Demo: Sniff for FireBug You may have noticed this message in your Gmail homepage recently: The reason for that is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple test to see if users have <a href="http://www.seifi.org/firebug/firebug_tips_and_tricks.html">Firebug</a> installed on their browsers. Obviously this would also weed out non-FireFox users.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">console</span> <span style="color: #339933;">&amp;&amp;</span> window.<span style="color: #660066;">console</span>.<span style="color: #660066;">firebug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;found Firebug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;can't find Firebug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-608"></span><br />
Demo: <a href="javascript:if(window.console &#038;&#038; window.console.firebug){alert('found Firebug');}else{alert('can\'t find Firebug');}">Sniff for FireBug</a></p>
<p>You may have noticed this message in your Gmail homepage recently:<br />
<img src='http://www.seifi.org/wp-content/uploads/2007/11/gmail_firebug_issue.gif' alt='Gmail Doesn’t Like Firebug' /></p>
<p>The reason for that is Firebug by default logs all XMLHttpRequests made for all the websites you visit. The problem is that the data that is logged never gets disposed of or cleared out.  Therefore, FireFox having to collect and store that information and the memory for Firefox will eventually get large enough that will cause your computer to start using paged cache. This will then make Gmail seem like you are swimming through molasses. Gmail by default seems to make 22 XMLHttpRequests when I load the main page. It then makes a new XMLHttpRequest every 30 seconds, to check for new emails, so in the span of 1 hour you will have 120 new Ajax calls tacked on. This is a nice feature of Gmail which makes life simple for its users (Notice there is no &#8220;Get new mail&#8221; button anywhere). But now every new Ajax call is another 1kb of data which adds to the memory usage and tacks on more CPU and RAM consumed by Firebug.</p>
<p>No need to worry though since, another nice feature of Firebug is that you can disable it on a domain name basis. </p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/11/disable_gmail_firebug.gif' alt='How to disable Firebug for any domain name ex) mail.google.com' align="left" hspace="10" vspace="3" /> To turn off Firebug for mail.google.com first open Firebug by hitting the green icon or F12. Click on the bug icon in the top left and choose the second option labeled &#8220;Disable Firebug for mail.google.com&#8221;. Now Firebug will be turned off and the green icon will be changed to a silver icon for this domain. You should notice a smoother and faster Gmail experience. You can also turn it back on by clicking on the link &#8220;Enable Firebug for this website&#8221;.</p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/11/allowedsites.gif' alt='Allowed Sites…' align="right" hspace="10" vspace="3" /> The other and better method of speeding up your Firefox and still keeping Firebug around, is to disable Firebug all together and enable it for specific sites that you are working on. To disable Firebug, again you click on the Bug icon and this time choose the first option &#8220;Disable Firebug&#8221;.<br />
Now visit any site that you would like to use Firebug on and then &#8220;right click&#8221; on the silver icon on the bottom and choose &#8220;Allowed Sites&#8230;&#8221; From here you can add the domain name for any sites you want to override. This makes your life easier and makes general surfing faster in FireFox, yet allows for using the powers of the almighty Firebug when needed.</p>
<p>If your application is similar to Gmail where XMLHttpRequests are called in a loop you may want to use the sniff script to warn users to disable Firebug for your domain as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/sniff-and-disable-firebug-howto-gmail-example.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Advanced Blog Stats From Clicky</title>
		<link>http://www.seifi.org/searching/advanced-blog-stats-from-clicky.html</link>
		<comments>http://www.seifi.org/searching/advanced-blog-stats-from-clicky.html#comments</comments>
		<pubDate>Fri, 31 Aug 2007 07:07:34 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/advanced-blog-stats-from-pmetrics.html</guid>
		<description><![CDATA[I&#8217;ve been using Clicky from Performancing Inc. for the past few weeks now and I had to write this review to let everyone know about this amazingly powerful, unique and advanced statistical package that you should be using on your blog. Personally I have used many other statistics packages including Google Analytics, and many other [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Clicky from Performancing Inc. for the past few weeks now and I had to write this review to let everyone know about this amazingly powerful, unique and advanced statistical package that you should be using on your blog. Personally I have used many other statistics packages including Google Analytics, and many other stats packages for WordPress, but none of them have been as valuable as Clicky, and I find myself going back to it over and over again. </p>
<p><span id="more-592"></span></p>
<p>Here are top 7 reasons why you really should check out Get Clicky.</p>
<p><strong>1. </strong>Spy</p>
<p>Spy is a live view of visitors interacting with your web site. Its like having your own <a href="http://labs.digg.com/bigspy/" target="_blank">digg like spy page</a>. This gives you the power of knowing in real time when and where your visitors are coming from, what pages they are visiting and where they are going when they leave. You see the user IP address as well as their browser and operating system. You can even trace specific users and see a breakdown of the history of their visits and actions made on the site. For each visitor you also see a nice set of stats such as their browser, operating system, language, resolution and whether JavaScript is enabled. As a side note Clicky works regardless of JavaScript support using image source loading.</p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/08/spy.gif' alt='Spy' /></p>
<p><strong>2. Tagging and Filtering</strong></p>
<p>You can go a bit further with IP address tracking in Clicky. You can tag certain IP addresses so you can easily identify them. You can also filter out specific IP addresses from the stats. For example If you want to exclude your own hits to your blog from being counted in your stats, enter the IP address(es) you use regularly and have them filtered out.</p>
<p><strong>3. </strong>RSS</p>
<p>Stats via RSS is another amazing feature that gives you the power of keeping a tab on your site.  Clicky gives you customizable RSS feeds that are updated every 30 minutes. Using these RSS feeds you are able to for example take a quick look at the action on your blog from any RSS reader. Now you can easily monitor the recent incoming links, popular incoming links, popular urls, recent searches, popular searches, recent visitors and dashboard data. A cool trick you can try is to change the duration for a feed.  For example to see the hits in the past hour, append hours=1 to the feed url. Or to see popular incoming links in the past week append days=7 to the feed url. Another neat feature of the RSS feed is that it obviously doesn&#8217;t require authentication, so you can share the url with others as you wish and or transform the RSS data and publicly display your stats on your blog.</p>
<p><strong>4. Clouds, CSV, XML, JSON, API</strong></p>
<p>Stats data is presented to you in tabular format by default, however you can easily change the view of any table to a cloud view by clicking on a little cloud icon. I find the cloud visual more useful, especially when looking at long tables of data. For example, the Search keywords page in cloud view easily highlights the most popular search terms and search engines that are sending you traffic. For offline viewing you can also download your stats in popular formats such as CSV for Excel, and also XML or JSON which can be useful for feeding them to your own applications. If you are comfortable with programming, you can even use the <a href="http://www.getclicky.com/help/api" target="_blank">API</a> provided to access the data from Clicky using your sitekey and site_id.</p>
<p><strong>5. Powerful Dashboard</strong></p>
<p>You can edit your main dashboard page to see the blocks that you are most interested in. By default you get the basics, Links, Searches, and Content. I also like Recent Visitors and Locale.  On the Basics widget a summary stats table gives you the birds eye view of what is going on. You see the number of visitors, the number of actions performed, total time spent on your blog, as well as averaged numbers such as Average actions per visit and Average time per visit. If that wasn&#8217;t enough you also see a comparison percentage column which shows you how today&#8217;s stats compare against the previous day&#8217;s data, or the same day last week.</p>
<p><img src='http://www.seifi.org/wp-content/uploads/2007/08/basics.gif' alt='Basics' /></p>
<p><strong>6. Google Maps</strong></p>
<p>For those of you that like to see geographical data, Google Maps is very nicely intergrated into Clicky in a few places. You can see the geolocation of any specific user as well as the locations of all visitors to your site on the map.</p>
<p><strong>7. WordPress Plugin</strong></p>
<p>If you use WordPress, and you should be, this plugin automatically puts your tracking code at the bottom of all pages on your site and filters out all traffic from site admins like yourself. It also does the whole &#8216;custom data tracking&#8217; thing to automatically name your visitors inside the Clicky interface based on what they entered on your comment form.</p>
</p>
<p></p>
<p>There are a ton of other features that I don&#8217;t have time to go into here, such as tracking custom data, tracking downloads, FeedBurner integration, HTTPS support and more. You can try out a <a href="http://www.getclicky.com/stats/home?site_id=32020" target="_blank">demo</a> of a sample tracking site to get a feel for the clean and easy to use user interface. </p>
<p>When you first register, you get 21 days of premium service free, so you can try out all the features. You can track up to 3 web sites and 1,000 daily page views per day per site for Free.  Beyond that level there are reasonably priced premium services which get you more sites, more features, and higher traffic levels &#8211; starting at less than $2/month.</p>
</p>
<p><a title="Clicky Web Analytics" href="http://getclicky.com/44763" target="_blank"><img alt="Clicky Web Analytics" src="http://static.getclicky.com/media/links/clicky-125.gif" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/searching/advanced-blog-stats-from-clicky.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Request and Response JavaScript</title>
		<link>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html</link>
		<comments>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html#comments</comments>
		<pubDate>Fri, 27 Jul 2007 02:43:37 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.seifi.org/ajax/simple-ajax-request-response-javascript.html</guid>
		<description><![CDATA[Here is the simple form of an AJAX call made to an XML document, parsing through the returned document and and grabbing the a specific node from the DOM. There is a try/catch clause to handle the 4 different sets of XMLHTTP objects for different browsers. The callback function is called once the response is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the simple form of an AJAX call made to an XML document, parsing through the returned document and and grabbing the a specific node from the DOM. There is a try/catch clause to handle the 4 different sets of XMLHTTP objects for different browsers. The callback function is called once the response is returned as 4+200 and the response is rendered to the user. Below is the JavasScript code snippet. <span id="more-591"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> XMLHttpArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> createXMLHTTPObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> xmlhttp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>XMLHttpArray.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
                        xmlhttp <span style="color: #339933;">=</span> XMLHttpArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> xmlhttp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> AjaxRequest<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>callback<span style="color: #339933;">,</span>method<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> req <span style="color: #339933;">=</span> createXMLHTTPObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">onreadystatechange</span><span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>req.<span style="color: #660066;">readyState</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>req.<span style="color: #000066;">status</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
                callback<span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        req.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>method<span style="color: #339933;">,</span>url<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User-Agent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'My XMLHTTP Agent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        req.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> AjaxResponse<span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> respXML<span style="color: #339933;">=</span>req.<span style="color: #660066;">responseXML</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>respXML<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> respVAL<span style="color: #339933;">=</span>respXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'family'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>
.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'result'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> respVAL<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> ClearResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        mdiv<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mdiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span>
<span style="color: #003366; font-weight: bold;">function</span> MakeRequst<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        AjaxRequest<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax.xml&quot;</span><span style="color: #339933;">,</span>AjaxResponse<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;get&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">////</span></pre></div></div>

<p></p>
<p>And our sample XML file looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;family</span> <span style="color: #000066;">result</span>=<span style="color: #ff0000;">&quot;successful ajax request &amp;amp; response!&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parents<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;father</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Mike&quot;</span> <span style="color: #000066;">last</span>=<span style="color: #ff0000;">&quot;Brady&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mother</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Carol&quot;</span> <span style="color: #000066;">last</span>=<span style="color: #ff0000;">&quot;Martin&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parents<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Greg<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Peter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Bobby<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/son<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Marcia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jan<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cindy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/daughters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maid</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Alice&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/family<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></p>
<p>Here is a working sample of this code.</p>
<div id="status" style="border:10px solid #eee;background:#ccc;width:300px;padding:10px 5px;margin:5px 0;">
</div>
<p><button onclick="return MakeRequst();">Ajax Request</button> <button onclick="return ClearResponse();">Reset</button><br />
<script type="text/javascript" src="http://www.seifi.org/apps/simpleajax/ajax.js"></script></p>
<p>Some things to note are:</p>
<p>I&#8217;m using a GET here, but yo can easily change that to a POST in the call to AjaxRequest.</p>
<p>The URL passed to AjaxRequest can contain parameters as needed.</p>
<p>You can handle other readyStates(0,1,2,3) and <a href="http://www.w3.org/Protocols/HTTP/HTRESP.html">HTTP status codes</a> as you wish using the onreadystatechange handle. </p>
<p>I am sending null since I am not posting anything back to the server, but you can swap that with your own Post data if you wish. To set that up you have to also add this line of code before you call send to set the proper <a href="http://w3.org/Protocols/HTTP/HTRQ_Headers.html">request headers</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">req.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Content-type'</span> <span style="color: #339933;">,</span> 
<span style="color: #3366CC;">'application/x-www-form-urlencoded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></p>
<p>The responseXML property is only available when the request is made to an XML document, so If you are using other document types (HTML,Text,CSV,JSON) you will not have access to this property. If you use anything other than XML data you will have access to the responseText property instead.</p>
<p>Once you have the handle to the responseXML property, you can traverse through the XML DOM like you would with any other DOM object and you can use all the <a href="http://developer.mozilla.org/en/docs/DOM:element">DOM element methods, properties and events</a> that you already know.</p>
<p>For example to get a list of all the sons in the family we can do:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">respSONS<span style="color: #339933;">=</span>respXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;son&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
respSonVals <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">&lt;</span>respSONS.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    respSonVals <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> respSONS<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<p>Try <a href="" onclick="return getSons()">Get Son Names</a></p>
<div id="domvals" style="border:10px solid #eee;background:#ccc;width:300px;padding:10px 5px;margin-bottom:5px;">Results Go Here:</div>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/javascript/simple-ajax-request-response-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.041 seconds -->
