Chapter 4
Serious Ajax Programming
IN THIS CHAPTER
- Handling multiple XMLHttpRequest requests
- Using two XMLHttpRequest requests
- Using an array of XMLHttpRequest requests
- Using inner functions and multiple XMLHttpRequest requests
- Handling JavaScript sent from the server
- 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.
You're also going to see that in addition to text and XML data, some Ajax applications return JavaScript for you to execute. That's often the case when you connect to a large-scale Ajax-based ...
Get Ajax Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.