Datasheet

You could then insert the XHTML document fragment into the HTML page dynamically to update the
page.
XSLT is another standard maintained by W3C. Both IE and Mozilla have XSLT processors; however, they
don’t always treat their XSLT documents in the same way. XSLT uses another language, XPath, to query
the XML document when applying its transformations. XPath queries are used to address elements
within the original XML document, such as the following:
<xsl:for-each select=”//Hotel”>
The //Hotel statement instructs the browser’s XSLT processor to look for elements called <Hotel> that
are descendants of the root element
<HotelList>. XPath queries can be used to locate specific items or
groups of items within an XML document, using a syntax that is superficially similar to the way
browsers can locate web pages, with the following as an example:
//HotelList/Hotel/Rooms
These techniques can be used to retrieve sections of data and display it on the page using the browser.
Again, they are able to offer instantaneous updates without the need for a trip back to the server. Both
XSLT and XPath are discussed in more detail in Chapter 8.
The XMLHttpRequest Object
If there’s one thing you haven’t come across before, it’s likely to be the XMLHttpRequestObject.
Microsoft introduced quite an obscure little ActiveX control in Internet Explorer version 5 (IE 5) called
the
XMLHttp object. Of course, ActiveX controls are tied to IE, so shortly afterward, Mozilla engineers
followed suit and created their own version for Mozilla 1 and Netscape 7, the corresponding
XMLHttpRequest object. The status of these objects was elevated considerably because of their inclusion
in the original Ajax article. They are now more commonly referred to singularly as the
XMLHttpRequest
object, and, in IE 7, there is a native XMLHttpRequest object in addition to the ActiveX Control. Versions
of this object have been included in Safari 1.2 and Opera as well.
But what does it do? Well, it allows a developer to submit and receive XML documents in the back-
ground. Previously, you could use hidden frames or IFrames to perform this task for you, but the
XMLHttpRequest is rather more sophisticated in the ways in which it allows you to send and pick up
data.
Unfortunately, because it isn’t yet standard, that means there are still two separate ways of creating it. In
versions of IE prior to version 7, it is created as an
ActiveXObject in JavaScript as follows:
var xHRObject = new ActiveXObject(“Microsoft.XMLHTTP”);
There are several versions of the MSXML library with respective ProgIDs to instan-
tiate
XMLHttp object. Specifically, you cannot instantiate any version of XMLHttp
object higher than ‘Msxml2.XMLHTTP.3.0’ with the given version independent
ProgID Microsoft.XMLHTTP. For the examples in this book, though, this will be
sufficient.
14
Chapter 1: Introducing Ajax
04_106754 ch01.qxp 2/9/07 6:15 PM Page 14