(^182) ❘ CHAPTER 7 AJAX
Requesting Data Formatted in XML
The fi rst example I demonstrate shows you how to request data from a server that formats the
response as XML. The following source code demonstrates an input form for an address in which
the country fi eld causes the state fi eld to be dynamically updated when the country selection is
changed and the country’s fl ag is changed as well. Each list of states is dynamically fetched from
the server using an AJAX request. However, this happens only for three of the country selections—
the United States, Canada, and the United Kingdom—because the information is fed from static
XML fi les rather than a database-driven server. If I were to create an XML fi le for all 239 country
options, I would at least change the fl ag for that country, even if no administrative subdivision simi-
lar to a state exists for that country. The following is the HTML portion of Example 7-1:
<!DOCTYPE HTML>
elliott
(Elliott)
#1