Datasheet

What really happens in this example is that Ajax downloads the name of the new image to display.
Then, the example uses JavaScript to rewrite an HTML
<img> element in the Web page, using the
name of the file to download. When the browser sees that the
<img> element has been rewritten,
it downloads the image the
<img> element references, through the magic of dynamic HTML.
The end result is that you click a button and a new image appears, no browser refresh needed.
That’s a combination of Ajax and dynamic HTML at work, and it indicates that you will indeed be
able to download binary data using Ajax in this book.
Drag and drop with Ajax
As Web applications become more and more like desktop applications, more and more of what
you take for granted in desktop applications is going to start showing up in online applications.
For example, drag-and-drop operations can make life a lot easier for the user; and now, when you
drag-and-drop items in a Web page, the server can be notified of what you’ve done behind the
scenes. That means the next time you take a look at the page, what you’ve dragged and dropped
appears in the new position you’ve placed it.
For example, take a look at the refrigerator magnet words at
www.broken-notebook.com/
magnetic/
, shown in Figure 1.20.
When you drag a “magnet” to a new location, that new location is sent to the server using Ajax
techniques, and that location data is stored. Other people navigating to the page see the magnets in
the locations you have set them, and when you come back to the page, the magnets will be where
you placed them unless someone has already moved them.
FIGURE 1.20
The refrigerator magnet words stay where you placed them unless someone else comes along and moves
them.
18
Fundamental Ajax
Part I
06_102633 ch01.qxp 2/23/07 9:44 PM Page 18