Processing XML Data from AJAX Responses with JavaScript
(Page 1 of 4 )
Developing AJAX-driven applications can be an educational experience, particularly for those web developers who are taking their first steps into this exciting area. However, on the other hand, it can also be hard, specifically when it comes to deciding which output format should be used for delivering the results of AJAX-based http requests to end users. This article offers one sensible approach.
Introduction
Welcome to the final installment of the series that began with "Parsing AJAX responses with JavaScript." In order to address the aforementioned issue, this series demonstrates different approaches that can be used to process AJAX responses, ranging from handling data delivered in plain text format, to parsing entire XML documents.
Now that I've introduced you to the subject of this series, I'd like to refresh your memory of the topics that I covered in the preceding article. This will help you to see the continuity between that tutorial and this one, which hopefully you're reading with careful attention.
Put in a simple way, you'll remember that in the previous article of the series, I developed a simple AJAX application whose primary functionality was displaying on the browser a set of database records. These records were fetched from a sample database table by using a couple of PHP 5 classes. It's worth mentioning here that these database rows were rotated at a predefined time interval, in this case utilizing a simple JavaScript timer.
Of course, the most important thing to note here, beyond the programmatic logic implemented by this AJAX-based application, is that each database record was parsed in the client by utilizing a few common DOM methods. This illustrated that it is perfectly plausible to use a standard approach to parse AJAX responses.
Nonetheless, even when the AJAX technology exposes only two primary properties for fetching data from the server, named "responseText" and "responseXML" respectively, I have to admit that the subject is really huge and quite challenging. Thus, considering that hopefully you grasped the different techniques that I developed in the two previous articles of this series for parsing AJAX responses served as plain text, in this last tutorial I'm going to show you how to process these responses utilizing the "responseXML" property. Sounds quite interesting, right?
With the preliminaries out of our way, now let's find out how to parse AJAX responses that are delivered in XML. Let's get started!
Next: Preparing the scenario for parsing XML data >>
More JavaScript Articles
More By Alejandro Gervasio