Datasheet

Creating an Ajax application is about the design and thinking about how the user interface and experi-
ence will be improved by your application. We’re going to create a quick example that shows how you
can use the
XMLHttpRequest object and XML files to create a dynamic menu system for a business sce-
nario.
The business scenario is this. You have a travel company whose web site displays information about
hotels and suites. The hotels wish to display booking information about only those suites that currently
are available. This information is published as an XML file. It is quite common for companies to publish
data as text or XML files to the same location at a given interval because it can usually be generated
automatically. This example does not create the facility to publish the XML file, but rather checks and
fetches new data from a given location every 10 seconds. This, in turn, will have the effect of updating
the options on the menu system without the need for a page refresh.
Note that this example is quite complex. It demonstrates a meaningful way in which Ajax can be used.
You should skim over the code. Later chapters discuss the
XMLHttpRequest object, the use of the DOM,
and scenarios in which you can use XML and XSL in your applications.
Try It Out First Ajax Example
1.
Create a new folder in your web server’s root directory called BegAjax. Inside that, create a
folder called
Chapter1.
2. You will start by creating the data file in XML. Save this as SuiteList.xml in the Chapter1
folder. Note that all of these files can be created in Notepad or your preferred text or web page
editor. If you don’t wish to type the code in, it can be downloaded from
www.wrox.com in the
Downloads section.
<?xml version=”1.0” encoding=”utf-8” ?>
<SuiteList>
<Suite>
<SuiteID>1001</SuiteID>
<Name>Ponderosa</Name>
<Size>2</Size>
<Price>50</Price>
<WeeksFree>10</WeeksFree>
</Suite>
<Suite>
<ProductID>1002</ProductID>
<Name>Colenso</Name>
<Size>2</Size>
<Price>30</Price>
<WeeksFree>10</WeeksFree>
</Suite>
<Suite>
<ProductID>1003</ProductID>
<Name>Dunroamin
</Name>
<Size>2</Size>
<Price>60.00</Price>
<WeeksFree>10</WeeksFree>
</Suite>
21
Chapter 1: Introducing Ajax
04_106754 ch01.qxp 2/9/07 6:15 PM Page 21