Chapter 4. Sending and Receiving Data

In This Chapter

  • Summarizing XML

  • Generating an XML response

  • Traversing XML with JavaScript

  • Introducing JSON

AJAX can be used to send information to the client from the server. Elsewhere in Book VII, I concentrate on using complete XHTML code that can be integrated directly into the page. There's another powerful way to work with AJAX. You can pass data around in a specialized format and let the JavaScript/jQuery code manipulate the data on the client. The data is usually packed in XML format, but JSON is an increasingly popular technique. Both systems are introduced in this chapter.

Working with XML

eXtensible Markup Language (XML) is an extremely useful tool for sending and receiving data. XML data is easy to read and understand, even by humans. It's not too difficult to write programs that can read XML data, and the structure of the data is preserved by the tags. When you create your own XML format, you define custom tags to describe the data as follows:



XML is nothing new if you've read any other part of this book. XHTML is simply a form of HTML that also follows XML rules. The new idea is this: Rather than having to conform to somebody else's list of tags, you can invent your own and transmit information using your custom XML syntax.

These tags can be parsed with JavaScript and generated with PHP fairly easily.

Every XML element ...

Get HTML, XHTML, and CSS All-In-One Desk Reference For Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.