Section 2.27. Podcasting Studio


2.27. Podcasting Studio

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.

Web Browser: Sure, I'd love to talk about that. In fact, ready states are one of the few areas where people actually notice me. Most of the time, everyone would rather talk about JavaScript and PHP.

HeadRush: Well, those are awfully important programming languages...

Web Browser: Sure, sure, but what good is JavaScript without me and Callback? I mean, without us, JavaScript is just a bunch of funny looking lines of text.

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: Yeah, that's the one you assign to the request object 's onreadystatechange property, right?

Web Browser: Exactly. Well, that's Callback. He's a special type of function: a callback function. But I usually just say, "Callback!", and he comes running.

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!




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net