Java Reference
In-Depth Information
When using hidden frames, a popular Ajax approach, with these browsers, you'll notice few differences
in the code, as each Browser Object Model (BOM) handles frames the same way (frame-based Ajax is cov-
ered later in the chapter). However, when you start using other forms of Ajax, such as XMLHttpRequest,
the differences in code become apparent.
Using the XMLHtt pRequest Object
As stated before, there are a variety of ways you can create Ajax-enabled applications. However, probably
the most popular Ajax technique incorporates the JavaScript XMLHttpRequest object, which is present in
all major browsers.
Despite its name, you can retrieve other types of data, like plain text, with XMLHttpRequest .
The XMLHttpRequest object originated as a Microsoft component, called XmlHttp, in the MSXML
library fi rst released with IE 5. It offered developers an easy way to open HTTP connections and
retrieve XML data. Microsoft improved the component with each new version of MSXML, making it
faster and more effi cient.
As the popularity of the Microsoft XMLHttpRequest object grew, Mozilla decided to include its own
version of the object with Firefox. The Mozilla version maintained the same properties and methods
used in Microsoft's ActiveX component, making cross-browser usage possible. Soon after, Opera
Software and Apple copied the Mozilla implementation, thus bringing the easy-to-use object to all
modern browsers.
Cross-Browser Issues
The XMLHttpRequest object is no different from other web standards supported by the browsers, and
the differences can be divided into two camps: ActiveX (for IE 5 and 6) and native support (for all other
browsers). Thankfully, the two browser types only differ when you need to create an XMLHttpRequest
object. After the object's creation, the remainder of the code is compatible for every browser.
Using ActiveX
Because the XMLHttpRequest object originated as a part of the MSXML library, an ActiveX XML parser,
instantiating an XMLHttpRequest under these browsers, requires the creation of an ActiveX object. In
Chapter 12, you created ActiveX objects to traverse the XML DOM. Creating an XMLHttp object isn't
much different.
var oHttp = new ActiveXObject(“Microsoft.XMLHttp”);
This line creates the fi rst version of Microsoft's XMLHttpRequest. There are many other versions of
Microsoft's XmlHttp, but Microsoft recommends using one of the following versions:
MSXML2.XmlHttp.6.0
MSXML2.XmlHttp.3.0
Search WWH ::




Custom Search