XML Tutorials

  Home arrow XML Tutorials arrow Page 4 - Handling Data for Ajax with JSON
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 / 5
    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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    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.
    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - 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-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap