Java Reference
In-Depth Information
Despite the fact that the XMLHttpRequest object has the XML acronym as part
of its name, it does not require that you use XML. You can use the XMLHttpRequest
object to exchange text information just as well as XML. However, if you are using XML, the
XMLHttpRequest object will conveniently package the incoming XML with the DOM.
The XMLHttpRequest object is not the only method that can be used to exchange
information with the web server. Another common technique is to use an <iframe> . The
<iframe> tag allows you to embed one web page inside of another.
The <iframe> tag has a URL that defines what HTML it is to display. This URL prop-
erty can be modified with JavaScript. If the URL is modified, the <iframe> will load the
data contained at the new URL. Some sites simply hide the <iframe> and change its URL
to the page that they would like to retrieve a message from. The browser will then fill the
<iframe> element with the data received from the URL. The JavaScript can then harvest
the data. Because the <iframe> element is hidden, the user will not see any of this.
Interpreting XML
XML is an ideal protocol to exchange information between the web server and the AJAX
program running on the web browser. Because the DOM can easily parse XML, JavaScript is
very well equipped to handle XML messages.
To see what XML messages might be sent, consider an AJAX web application that main-
tains an employee database. One such function that an AJAX application would need to im-
plement would be an employee search. Consider an employee search function where the
user enters the first and last name of an employee and the system attempts to locate that
employee's record.
For such a system, the AJAX application running on the web browser would construct
and send an XML message similar to the following:
<request type="employeeSearch">
<searchFor>
<first>John</first>
<last>Smith</last>
</searchFor>
</request>
When the server sends back the requested employee, it will be as an XML message. The
following message could be sent back:
<response type="employeeSearch">
<employee>
<first>John</first>
<last>John</last>
<phone>636-555-1212</phone>
<address>102 Main Street</address>
Search WWH ::




Custom Search