<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>waelchatila.com - AJAX category</title>
  <link>http://waelchatila.com:80/categories/ajax/</link>
  <description>Notes on Software, Engineering and Science</description>
  <language>en</language>
  <copyright>Wael Chatila</copyright>
  <lastBuildDate>Thu, 11 Mar 2010 03:23:48 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Turn your roomba into a walking google bot </title>
    <link>http://waelchatila.com:80/2010/03/01/1267514760000.html</link>
    
      
        <description>
          When my latest son was born I got a little worried since he didn&#039;t look at all like me. I decided I needed a discrete device to spy on my wife while I was at work. I started hacking my roomba and made a  &lt;b&gt;G&amp;#229;&amp;#229;gleBot&lt;/b&gt; (pronounced &lt;i&gt;/google-bot/&lt;/i&gt;). G&amp;#229;&amp;#229;gleBot is a &#034;home crawler&#034; consisting of a vacuum roomba with an on board webserver and camera.
        While the vacuum goes about its business, it extracts text from the images it takes.
        The text is later put in a database on the roomba and searchable through a web interface. This was a good pretext for my wife. I, of course, also added the ability to remote control the roomba using AJAX...for spying purposes...hehe.

&lt;br/&gt;
&lt;a href=&#034;http://www.gaaglebot.com&#034;&gt;&lt;img src=&#034;http://www.gaaglebot.com/building/r2.jpg&#034; alt=&#034;GaagleBot&#034;/&gt;&lt;/a&gt;
&lt;br/&gt;
I created a dedicated site for the little fellow for fun with showcase app. &lt;a href=&#034;http://www.gaaglebot.com&#034;&gt;http://www.GaagleBot.com&lt;/a&gt;
&lt;br/&gt;
&lt;br/&gt;
This is the next version of &lt;a href=&#034;http://waelchatila.com/2006/07/13/1152788433678.html&#034;&gt;My AJAX Lego Robot&lt;/a&gt;.
I&#039;m working on yet another version of my AJAX Remote Controlled thingies...stay tuned.
        </description>
      
      
    
    
    
    <category>AJAX</category>
    
    <category>Hardware</category>
    
    <category>Java</category>
    
    <category>Games &amp; Fun</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2010/03/01/1267514760000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2010/03/01/1267514760000.html</guid>
    <pubDate>Tue, 02 Mar 2010 07:26:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Internet Explorer 6 &amp; 7 document.domain bug</title>
    <link>http://waelchatila.com:80/2007/10/31/1193851500000.html</link>
    
      
        <description>
          &lt;b&gt;Disclaimer:&lt;/b&gt; Im not sure this a bug discovery...couldn&#039;t find anything that resembled it after a couple of minutes of googling, or a super silly security restriction.
&lt;p&gt;
I&#039;ve been coding some javascript ajax code that inserts an iframe, and into the created iframe, inserts a form and submits the form to a (cross domain) server. This is an old cross-domain ajax technique by now, but while implementing it I came across this ridiculously annoying bug in IE. The line in red below will result in an &#034;Access Denied&#034; exception being thrown...again, only in IE. Tried this with IE6 under WinXP Media Center Edition SP2, IE7 under WinXP Home Edition SP2, and IE7 Windows Vista Home. Needless to say...it works just fine in FireFox.

&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;script type=&#034;text/javascript&#034;&amp;gt;
  document.domain = &#039;waelchatila.com&#039;;
  var new_html = &#039;&amp;lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&amp;gt;&amp;lt;/iframe&amp;gt;&#039;;
  document.body.innerHTML+=new_html;
  try {
    var iframe_doc = &lt;font color=&#034;red&#034;&gt;document.getElementById(&#034;frm&#034;).contentWindow.document;&lt;/font&gt;
  } catch (e) {
    alert(e);
  }
&amp;lt;/script&amp;gt;
&lt;/div&gt;
&lt;div id=&#034;frm1&#034;&gt;&lt;/div&gt;
&lt;script type=&#034;text/javascript&#034;&gt;
function insertIframe() {
        document.domain = &#039;waelchatila.com&#039;;
            var new_html = &#039;&lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&gt;&lt;/iframe&gt;&#039;;
            document.getElementById(&#039;frm1&#039;).innerHTML+=new_html;
var bError = false;
try {
 var iframe_doc = document.getElementById(&#034;frm&#034;).contentWindow.document;
} catch (e) {
   bError = true;
}
alert(bError?&#034;Exception thrown&#034;:&#034;No exceptions thrown&#034;);
}
    &lt;/script&gt;


Try it by clicking the button below. &lt;p&gt;
&lt;button onclick=&#034;insertIframe();return false;&#034;&gt;Try it!&lt;/button&gt;
&lt;p&gt;
This page should be served off of &lt;i&gt;http://waelchatila.com&lt;/i&gt;. As you can see, the document.domain is explicitly set to the domain the page was served from. The iframe src is also from the same server. I&#039;ve tried it with a whole variety of variations, none of the demonstrated here but tested for.
&lt;ul&gt;
&lt;li&gt;iframe&#039;s document.domain = &#039;waelchatila.com&#039;;&lt;/li&gt;
&lt;li&gt;iframe src is empty&lt;/li&gt;
&lt;li&gt;iframe src is &#034;javascript:false&#034;&lt;/li&gt;
&lt;/ul&gt;
There should be no problem accessing the iframe&#039;s content in either case. 
&lt;p&gt;Now, if the &lt;i&gt;document.domain = &#039;waelchatila.com&#039;;&lt;/i&gt; line is removed, it works. In order for this to work, you&#039;ll need to reload this page if you clicked the previous button since document.domain has now already been assigned.

&lt;p&gt;
&lt;div id=&#034;frm2&#034;&gt;&lt;/div&gt;
&lt;script type=&#034;text/javascript&#034;&gt;
function insertIframe2() {
            var new_html = &#039;&lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&gt;&lt;/iframe&gt;&#039;;
            document.getElementById(&#039;frm2&#039;).innerHTML+=new_html;
var bError = false;
try {
 var iframe_doc = document.getElementById(&#034;frm&#034;).contentWindow.document;
} catch (e) {
   bError = true;
}
alert(bError?&#034;Exception thrown&#034;:&#034;No exceptions thrown&#034;);
}
    &lt;/script&gt;


&lt;button onclick=&#034;insertIframe2();return false;&#034;&gt;Try it!&lt;/button&gt;
&lt;p&gt;
The same results present itself if the iframe is created with &lt;i&gt;document.createElement(&#039;iframe&#039;)&lt;/i&gt; and &lt;i&gt;document.appendChild(...)&lt;/i&gt;
&lt;p&gt;
I&#039;ve yet to find a workaround for this issue. I&#039;ll be positing another entry if I found out how. Please let me know if you know of one!
        </description>
      
      
    
    
    
    <category>AJAX</category>
    
    <category>Windows</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2007/10/31/1193851500000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2007/10/31/1193851500000.html</guid>
    <pubDate>Wed, 31 Oct 2007 17:25:00 GMT</pubDate>
  </item>
  
  <item>
    <title>AJAX Remote Controlled Lego Robot</title>
    <link>http://waelchatila.com:80/2006/07/13/1152788433678.html</link>
    
      
      
        <description>
          This article shows how to remote control a real world lego robot using AJAX technology.&lt;p&gt;&lt;a href=&#034;http://waelchatila.com:80/2006/07/13/1152788433678.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;&lt;a href="http://waelchatila.com:80/2006/07/13/1152788433678.html"&gt;Read more...&lt;/a&gt;&lt;/p&gt;
        </description>
      
    
    
    
    <category>Unix/Linux</category>
    
    <category>C++</category>
    
    <category>AJAX</category>
    
    <category>Hardware</category>
    
    <category>Games &amp; Fun</category>
    
    <comments>http://waelchatila.com:80/2006/07/13/1152788433678.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2006/07/13/1152788433678.html</guid>
    <pubDate>Thu, 13 Jul 2006 11:00:33 GMT</pubDate>
  </item>
  
  <item>
    <title>W AJAX design pattern </title>
    <link>http://waelchatila.com:80/2006/07/08/1152426781706.html</link>
    
      
        <description>
          This is a new design pattern which was independently discovered by me and &lt;a href=&#034;http://www.jlamp.com&#034; rel=&#034;nofollow&#034;&gt;Will Glass&lt;/a&gt; over the phone one day while discussing a painful loading time of around 7 seconds for a web application we were working on.
&lt;h2&gt;Describing the problem&lt;/h2&gt;
The web app front basically consists of a Google Map plus a form. The user can search for an address/place or, interactively on the map, select a boundary area for the search. When the search is submitted to the webserver, the webserver sends off an additional request to a 3rd party geodata server for the purpose of retrieving geocoding data plus demographical data. The problem is that this request to the 3rd party geocoding provider takes some time. The end result would be a wait for about 7 seconds between the time the search was submitted and the end resulting page showed up. The picture below depicts what&amp;rsquo;s going on &lt;center&gt;&lt;img alt=&#034;&#034; src=&#034;images/without_w.png&#034; /&gt;&lt;/center&gt; 1. User submits a search request with HTTP POST&lt;br /&gt;
2. A blocking request to the geodata server is issued&lt;br /&gt;
4. Geodata retrieved and results are sent back to the browser&lt;br /&gt;
5. Data received by browser&lt;br /&gt;
6. Browser finished processing and rendering the data and page fully displayed.&lt;br /&gt;
&lt;h2&gt;W AJAX Solution&lt;/h2&gt;
A way to reduce the response time is to utilize some AJAX. The idea is the following. When the search request arrives at the webserver, a new thread associated with the http session is spawned with the task to asynchronously do the 3rd party geodata request. Control is immediately returned back to the browser with no geodata. The browser, upon getting the no geocode data immediately sends of an AJAX request (asynchronous by nature) while it continues to render the web page with images, the Google Map, tables etc. This rendering takes some time to happen and by the time the rendering is done the AJAX request has landed at the webserver and is doing a blocking wait for the spawned geodata server request. When the 3rd party request is done, data is very quickly returned back to the browser (once again one of the natures of AJAX) and the rendered page is updated using DHTML. All in all reducing loading time, &lt;em&gt;but more importantly reducing perceived responsiveness for the user&lt;/em&gt;. &lt;br /&gt;
The picture below with accompanying steps describes more in detail how it works. &lt;center&gt;&lt;img alt=&#034;&#034; src=&#034;images/with_w.png&#034; /&gt;&lt;/center&gt; 1. User submits a search request with HTTP POST&lt;br /&gt;
2. A non-blocking request to the geodata server is issued in a spawned thread that is associated with the session. A web page layout with no geo data is returned to the browser.&lt;br /&gt;
3. Browser sends of an AJAX request with the purpose of retrieving geo data. Browser continues rendering the web page layout and elements.&lt;br /&gt;
4. AJAX request arrives at webserver and does a blocking wait for geo data to arrive. Geo data is finally calculated and results are sent back to the webserver. Webserver relays geo data to the AJAX request which returns.&lt;br /&gt;
5. Data is received by browser and presented in a quick manner using DHTML&lt;br /&gt;
&lt;h2&gt;Did it really work?&lt;/h2&gt;
Was the rendering that bad? and is the extra complexity worth it? It depends on the situation and application. In our case  we were able to squeeze down response time to around 3 seconds with the end result of a happy customer, in other words, it made a huge difference for us.
&lt;h2&gt;Why &amp;quot;W&amp;quot;?&lt;/h2&gt;
The calling pattern traced out in the image above resembles a &amp;quot;W&amp;quot; and an &amp;quot;U&amp;quot;, combine this with how &amp;quot;W&amp;quot; is pronounced in English and you get one visual &amp;quot;W&amp;quot; and, at least, one phonetic &amp;quot;U&amp;quot;. Besides, it&#039;s arguable the best way to start a name, what do you think Will? :)
        </description>
      
      
    
    
    
    <category>AJAX</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2006/07/08/1152426781706.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2006/07/08/1152426781706.html</guid>
    <pubDate>Sun, 09 Jul 2006 06:33:01 GMT</pubDate>
  </item>
  
  <item>
    <title>Using AJAX with CAPTCHA - AJAX Security Part 3 of 3</title>
    <link>http://waelchatila.com:80/2005/12/18/1134960510669.html</link>
    
      
      
        <description>
          This article shows one way to use AJAX along with a series of images to create a secure CAPTCHA system. CAPTCHA is a way to tell humans and computers apart and is used all over the web, especially if you&#039;re signing up for new email accounts.  For more background information and definitions, see &lt;a href=&#034;http://en.wikipedia.org/wiki/Captcha&#034;&gt;http://en.wikipedia.org/wiki/Captcha&lt;/a&gt;&lt;p&gt;&lt;a href=&#034;http://waelchatila.com:80/2005/12/18/1134960510669.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;&lt;a href="http://waelchatila.com:80/2005/12/18/1134960510669.html"&gt;Read more...&lt;/a&gt;&lt;/p&gt;
        </description>
      
    
    
    
    <category>AJAX</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2005/12/18/1134960510669.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2005/12/18/1134960510669.html</guid>
    <pubDate>Mon, 19 Dec 2005 02:48:30 GMT</pubDate>
  </item>
  
  </channel>
</rss>
