Recent articles:
Popular archives:
Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can,
or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing
heavily in Java's future as a platform for platforms
Also see:
Discuss: Tim Bray on 'What Sun Should Do'
In this article, you'll build a simple AJAX (Asynchronous JavaScript and XML) application. This exercise is for the most impatient readers willing to start coding ASAP, but it assumes you're already familiar with JavaScript, PHP, and XML.
You'll create here a simple AJAX Web application called quickstart, where the user is requested to write his or her name, and the server keeps sending back responses while the user is writing. Figure 1 shows the initial page, index.html, loaded by the user. (Note that index.html gets loaded by default when requesting the quickstart Web folder, even if the file name is not explicitly mentioned.)
While the user is typing, the server is being called asynchronously, at regular intervals, to see if it recognizes the current name. The server is called automatically, approximately one time per second, which explains why we don't need a button (such as a Send button) to notify when we're done typing. (This method may not be appropriate for real login mechanisms, but it's very good to demonstrate some AJAX functionality.)
Depending on the entered name, the message from the server may differ; see an example in Figure 2.
See Resources for a link to check out this example online.
Maybe at first sight, there's nothing extraordinary going on there. We've kept this first example simple on purpose, to make things easier to understand. What's special about this application is that the displayed message comes automatically from the server, without interrupting the user's actions. (The messages are displayed as the user types a name). The page doesn't get reloaded to display the new data, even though a server call needs to be made to get that data. This wasn't a simple task to accomplish using non-AJAX Web development techniques.
The application consists of the following three files:
Figure 3 shows the actions that happen when running this application:
Steps 1 through 5 are a typical HTTP request. After making the request, the user needs to wait until the page gets loaded. With typical (non-AJAX) Web applications, such a page reload happens every time the client needs to get new data from the server.
Steps 5 through 9 demonstrate an AJAX-type call—more specifically, a sequence of asynchronous HTTP requests. The server is
accessed in the background using the XMLHttpRequest object. During this period, the user can continue to use the page normally, as if it were a normal desktop application. No
page refresh or reload is experienced in order to retrieve data from the server and update the Webpage with that data.
Archived Discussions (Read only)