SunQuest
 
       JavaScript
  Home arrow JavaScript arrow Using DOM Scripting to Parse AJAX Response...
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Using DOM Scripting to Parse AJAX Responses with JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-11-06

    Table of Contents:
  • Using DOM Scripting to Parse AJAX Responses with JavaScript
  • Fetching some database records with AJAX
  • Using DOM scripting to parse plain text responses with AJAX
  • Listing the complete source code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using DOM Scripting to Parse AJAX Responses with JavaScript


    (Page 1 of 4 )

    For web developers who need to build AJAX-driven applications, parsing the output generated by a server-side script using the "responseText" and "responseXML" properties of HTTP XML Request objects can be a challenging task. This is particularly true in those cases where it's difficult to determine which format should be used for delivering this output in a readable form to end users. This article series shows you several good solutions.

    Introduction

    Welcome to the second part of the series that began with "Parsing AJAX responses with JavaScript." In response to the aforementioned issue, this series walks you through the development of several JavaScript-based approaches for processing as plain text or in XML format, the responses sent by a web server after performing an AJAX HTTP request.

    Now that I've introduced the primary objective of this series, let me do a brief recap of the topics covered in the first article. This will give you a better idea of how that tutorial will link with this one.

    In the preceding article of the series I illustrated in a hopefully friendly fashion how to use the neat "innerHTML" JavaScript property, from within the context of a simple AJAX application, to parse a group of MySQL database records which had been previously fetched with a couple of PHP classes.

    As you'll probably recall, this parsing process was indeed very straightforward. It was limited to extracting the mentioned database rows from a sample MySQL table with PHP, and then populating a determined (X)HTML container with the rows in question by using the handy "innerHTML" property.

    Of course, this approach, as everything in life, has some pros and cons. On one hand the utilization of the mentioned JavaScript property doesn't require creating new (X)HTML elements on the fly (via DOM scripting) to display server-side data on a concrete web document. On the other hand, however, the property in question isn't considered standard by the W3 Consortium, which could be a problem if you're a web developer who strongly prefers to stick to the W3C standards.

    In either case, using the "innerHTML" JavaScript property is probably the simplest method for parsing the response of an AJAX-based HTTP request returned from the web server as plain text. This doesn't mean that the topic ends here. There are a few other parsing approaches that deserve a close look. Therefore, in this second tutorial of the series I'll show you how to parse the data coming from an AJAX request by utilizing a completely standard approach, in this case via some DOM scripting.

    Indeed, the experience will be educational. By the end of this article you'll have a more solid background on how to parse an AJAX request returned in plain text, by using the functionality provided by the DOM. So, are you prepared to keep learning more on this exciting topic? Let's get going!

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this second chapter of this series, you’ll learn how to use the most common...
     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway