XML Tutorials
  Home arrow XML Tutorials arrow Page 4 - Handling Data for Ajax with JSON
IBM developerWorks
Try It Free
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
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? 
XML TUTORIALS

Handling Data for Ajax with JSON
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-01-10

    Table of Contents:
  • Handling Data for Ajax with JSON
  • Running the Application on Tomcat
  • Passing Data with JSON
  • Changing the JavaScript for JSON

  • 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
     
    Try It Free
     
    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

    Handling Data for Ajax with JSON - Changing the JavaScript for JSON


    (Page 4 of 4 )

    Now let's look at the client JavaScript code. I've replaced two functions with one: I removed msPopulate() and nonMSPopulate() , and now all browsers use the populateJSON() function shown in Example 4-12.

    Example 4-12. The populateJSON( ) function

    function populateJSON() {
        var jsonData = req.responseText;

        var myJSONObject = eval('(' + jsonData + ')');

        var decimal = document.getElementById('decimal');  
      decimal.value=myJSONObject.conversion.decimal;

        var hexadecimal = document.getElementById('hexadecimal'); 
        hexadecimal.value= myJSONObject.conversion.hexadecimal;

        var octal = document.getElementById('octal'); 
       octal.value=myJSONObject.conversion.octal;

        var binary = document.getElementById('bin');
      
    binary.value=myJSONObject.conversion.binary;

        var hyper = document.getElementById('hyper');
     
    hyper.value=myJSONObject.conversion.hyper;
    }

    Summary

    Remember that Ajax isn't a technology: it's a group of ideas that, used together, have proven very powerful. When you combine form manipulation with JavaScript, asynchronous callbacks withXMLHTTPRequest, and built-in XML with JSON parsers, you have something revolutionary--even though the individual pieces have been around for a while.

    Combine these client-side technologies with Javas established server-side technologies, such as servlets, Struts, and JSF, and you've got a really powerful basis for building a new generation of interactive web applications.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Ajax on Java," published by O'Reilly. We...
     

    Buy this book now. This article is excerpted from chapter four of the book Ajax on Java, written by Steven Douglas Olson (O'Reilly, 2007; ISBN: 0596101872). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax





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