Handling multiple XMLHttpRequest requests
Using two XMLHttpRequest requests
Using an array of XMLHttpRequest requests
Using inner functions and multiple XMLHttpRequest requests
Overcoming browser caching
In Chapter 3 you got your feet wet with Ajax by writing complete Ajax applications. This chapter takes over from there, giving you a working knowledge of the skills you’ll need to work through the rest of this book. In other words, you’re going to see some serious Ajax here.
This chapter starts by working with multiple XMLHttpRequest objects. For example, if you present the user with two buttons, each of which downloads different data from the server, you can’t count on the user to not press both buttons and wait for the results from the server. That’s a problem, because Ajax is asynchronous, remember? It doesn’t block execution of your code until it gets a result from the server. So if you have only one XMLHttpRequest object, and each time the user clicks a button you connect an anonymous function to its onreadystatechange property, which XMLHttpRequest request are you responding to-the one from the first button click or the second button click? You’ll tackle that problem first in this chapter.
|Cross Ref|| |
For an example of Google Suggest at work, see the example in Chapter 1, which used Google Suggest to display a drop-down list of possible matches to a partial search term. You can also find Google Suggest at www.google.com/webhp?complete=1&hl=en.
In addition, you’re going to see how to use Ajax with HTTP head requests, allowing you to check whether files exist on the server, what their length and creation date is, and more. And you’ll also see how to defeat caching in browsers like Microsoft Internet Explorer, and many other topics as you start getting into serious Ajax programming.