O'Reilly logo

Ajax Bible by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required