AJAX - The Complete Reference

(avery) #1

Chapter 2: Pre-Ajax JavaScript Communications Techniques 45


PART I


var average = xmlDoc.getElementsByTagName("average")[0].firstChild.nodeValue;
var total = xmlDoc.getElementsByTagName("votes")[0].firstChild.nodeValue;
var rating = xmlDoc.getElementsByTagName("rating")[0].firstChild.nodeValue;
/* get target div */
var target = document.getElementById(commObject.ui.outputTarget);
/* indicate vote was made and show result */
target.innerHTML = "Thank you for voting. You rated this a <strong>" +
rating + "</strong>. There are <strong>" + total + "</strong> total votes. The
average is <strong>" + average + "</strong>. You can see the ratings in the
<a href='http://ajaxref.com/ch2/ratings.txt' target='_blank'>ratings file</a>.";
}

This discussion should not be read as a criticism of XML, but rather a serious indication
that you need to choose the right transmission and response data format for the job. Given
the importance of such a decision, Chapter 4 is devoted solely to this topic.

File Uploads with Iframes
One aspect of iframes that will certainly come back later in the book is their involvement in
file uploads. In a standard Web browser, it is not possible to script the <input type="file"
/> field to read its contents. Before you get annoyed, consider that this really is a good thing

FIGURE 2-7 Iframes can send and receive almost anything.
Free download pdf