Java Reference
In-Depth Information
the browser's Back button. This might be a desired side-effect for some Ajax-enabled applications or
components, but it can cause serious usability problems for the user.
At the time of this writing, IE 8 is the only browser that logs requests made with an XMLHttpRequest
object in the history. One thing you have to keep in mind is that the Internet and browsers have been
around much longer than Ajax, and users have come to expect certain behavior when they click the
Back and Forward buttons. Breaking that behavior causes frustration for the user, and that's something
a responsible developer must take into account when designing their application.
Creating a Back/Forward-Capable Form with an IFrame
It's possible to avoid breaking the browser's navigational buttons by using an older Ajax technique:
using hidden frames/iframes to facilitate client-server communication. You must use two frames in
order for this method to work properly. One must be hidden, and one must be visible.
Note that when you are using an iframe, the document that contains the iframe is the visible frame.
The hidden-frame technique consists of a four-step process.
1.
The user initiates a JavaScript call to the hidden frame. This can be done by the user clicking a
link in the visible frame or some other form of user interaction. This call is usually nothing
more complicated that redirecting the hidden frame to a different web page. This redirection
automatically triggers the second step.
2.
The request is sent to the server, which processes the data.
3.
The server sends its response (a web page) back to the hidden frame.
4.
The browser loads the web page in the hidden frame and executes any JavaScript code to con-
tact the visible frame.
The example in this section is based upon the form validator built earlier in the chapter, but you'll use a
hidden iframe to facilitate the communication between the browser and the server instead of an
XMLHttpRequest object. Before getting into the code, you should fi rst know about the data received
from the server.
The following example does not work in Safari 2, as it does not log the history of
an iframe.
The Server Response
You expected only a few words as the server's response when using XMLHttpRequest to get data from
the server. The response in this example is different and must consist of two things:
The data, which must be in HTML format
A mechanism to contact the parent document when the iframe receives the HTML response
Search WWH ::




Custom Search