Section 6.5. more Frequently asked questions


6.5. more Frequently asked questions

Q:

That's it? The server sends back XML, and we just grab it using the responseText property?

A:

At its simplest, yes. But, as you're about to see, there's a lot more we can with XML than treat it as plain old text. So stick around...

Q:

How do we get the values out of the XML? That seems like it's going to be a pain in the butt.

A:

Yeah, you're right. Trying to break apart the XML datacalled parsing the XMLand getting the values out isn't very easy. Fortunately, there's a better way to work with XML than as plain text.

Q:

I remember something from way back in Chapter 2 about a responseXML property. Should we be using that instead of responseText?

A:

Boy, you were really paying attention, weren't you? Yes, the request object has a property called responseXML, and yes, it's a great idea to use that instead of responseText. But before we get that, it looks like we've got a visitor...

Hey there. Look, I know it's not my chapter, but I really think you might be interested in one of my DOM trees.

Oh my god. I'm finally starting to make some progress, and now Paul Bunyan wants to talk about selling me a bush.

Remember Mike from back in Chapter 4? He's the owner of the Webville tree farm.

Mike: Not a bush... a tree. And not just any tree; I've got a DOM tree you'd just love.

Server: Are you paying attention? Do you see me on this couch, and the nut with a notepad and bad accent? I'm not really looking to go into landscaping.

Mike: Well, I couldn't help but overhear you mention that you're sending XML back in your responses now.

Server: Yes, that's right... I really have communication issues, and Ziggy here thinks XML will help browsers allow me to say a lot more and still be understood.

Mike: Sounds like good advice to me. But how's a browser supposed to do anything with your XML? It's not that easy to parse an XML document, you know.

Server: What? Are you serious? You mean, all this work, and I'm still not going to be understood? Let me just find a toaster and a bathtub, and be done with it all!

Mike: That's what I'm here for, though! The browserand JavaScriptcan understand your XML. Any code that needs to read your XML response can just work with it using the DOM... and then everyone's happy.

Server: Yes! Well, let's get that DOM growing, then. I think I can see the light...




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