Pages:

These workshops assume you've looked through the lecture screencast, or that you already know, in general terms, what AJAX is. Here is a demo of AJAX (opens in new window)

Ajax Steps

These are a simplified representation of the steps in an Ajax process.
Click on each of the three steps below to see more detail about each one.

Note: you're not going to write any code at the moment, just review the three steps and try and understand the overview of what we're about to do.

step1 step2 step3

1: Create an xmlhttp object

Firstly we need to create an xmlhttp object to handle data returned by the web-server, the only problem is that Mozilla (the engine behind Firefox for instance) uses XMLHttpRequest and IE uses an ActiveX object that might be called Msxml2.XMLHTTP or Microsoft.XMLHTTP depending on the version of IE.

However, rather than test for the browser it's more robust to test for the functionality, we use a try...catch to first see if the browser is Mozilla, if that fails then check if it's the latest IE, and if it fails try an older IE. Of course if all three fail we're done for!

Here's some pseudocode that shows the outline idea:

create a variable called httpRequest
to hold the request object
if (window understands XMLHttpRequest) { // Mozilla, Safari
   httpRequest = new XMLHttpRequest object;
}
else if (window understands ActiveXObject) { // IE
   try to create {
      httpRequest = new ActiveX Object
                    using Msxml2.XMLHTTP;
   }
   catch any errors and do this instead {
      try to create {
         httpRequest = new ActiveX Object
                       using Microsoft.XMLHTTP;
      }
      catch any errors
   }
}
if (there is no httpRequest object by now) {
   alert('Giving up :( Cannot create an httpRequest');
}

Pages: