This example downloads and displays text from a server. (You’ll see what makes it tick in detail in the next chapter.) You can see this example in a Web browser in Figure 2.1.
Figure 2.1: An Ajax demo
When this application is hosted on a Web server, clicking the Fetch the Message button causes the application to use Ajax techniques behind the scenes to connect to the server and download the contents of a text file, data.txt. Here’s what’s in data.txt:
This text was fetched from the server with Ajax.
Clicking the button downloads the message from the server, without any page refresh needed. The downloaded text simply appears, as shown in Figure 2.2.
Figure 2.2: Downloading text using Ajax