This should create an output
that looks like Figure 5-7.
Figure 5-7. The final output after converting the XML document into HTML
Using DOM methods in this fashion can be very verbose. An alternative response to an
Ajax call is to return the entire HTML structure within an XML node. However, before getting
into that, it??™s extremely important that you understand how XML syntax works and behaves??”
especially with validity and encoding.
XML Validity and Encoding
XML is meant to be a very rigid language. No mistakes are allowed (it??™s affectionately known as
???Draconian error handling???). This is a good thing for the most part, but it can catch you if you
haven??™t considered a particular scenario of how it will be used. Take a look at the following two
examples and see whether you can see the problem:
CHAPTER 5 n AJAX AND DATA EXCHANGE 109
This is some content I want embedded on the pageThis is some content I want embedded on the pageNow, if you were using the preceding syntax to embed this onto the page, it might look
something like this:
var doc = transport.responseXML.documentElement; // grabs the root node
// get all myhtml nodes of which I have one
var embedhtml = doc.getElementsByTagName('myhtml')[1];
// Grab the element on the page in which to embed the html
var el = document.getElementById('placeholder');
el.innerHTML = embedhtml.
Pages:
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174