HeadRush: We're here today with the ever-popular Web Browser. Browser, we've been really looking forward to talking with you today.
Web Browser: Thanks for having me, HeadRush.
HeadRush: Let's begin by talking about requests and ready states. We get more questions on that topic than almost anything else these days.
HeadRush: Well, those are awfully important programming languages...
HeadRush: Wait a second... Callback? Who's that? I'm not really familiar with that term.
Web Browser: Callback? Oh, I bet you've heard of him, and just don't realize it. You know that function I'm supposed to run whenever a request's ready state changes?
HeadRush: OK, I'm with you. Callback... because you call him back?
Web Browser: Yes, you've got the idea now. I find out that something's happened with the request, and I "call back" that function. Then he can take care of all the details of handling the server's response.
HeadRush: So once you call back the ... err ... callback, then you're done?
Web Browser: No, not at all. In fact, I have to give Callback a holler several times for a typical request. And not only that, but I make sure he knows about anything the server said.
HeadRush: Oh, right, by using the request object.
Web Browser: Yup, you've got it down. I use the responseText property to let Callback know what the server said. I take care of the responseXML property, too, but I think that might be another chapter...
HeadRush: Yes, we're not quite there yet, but we'll get to that later. So when a callback function runs, it can get the server's response by using the responseText property?
Web Browser: Wait a second there... you're forgetting about something. I let Callback know every time something goes on in the request, not just when I've got a response. Callback knows better than to just use the request object without making sure the request is finished up. Otherwise, we'd end up in a big mess.
HeadRush: Because the server isn't done with the request...
Web Browser: ...and I haven't put the server's response into the request object. Speaking of which, I've got to take care of a ready state changing right now. Gotta run... cya later!