Home > Articles > Programming > Java

Advanced AJAX with JSON

Kris Hadlock
  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Kris Hadlock explains how to create complex JSON data transfers between the client and server, by using AJAX and the JSON parser.

There’s no doubt that AJAX is a powerful and user-enhancing group of technologies, but its many possibilities still aren’t widely known. In this article, we’ll take a look at how easy it can be to create an extremely powerful data transfer between the server and the client-side AJAX engine, using JavaScript Object Notation (JSON) and the JSON parser. We’ll explore how to create a group of objects (often referred to as a package in other languages), how to serialize the objects as JSON to be sent to the server, and how to deserialize server-side JSON as client-side JavaScript objects.

This article assumes that you understand JavaScript and how to create a basic AJAX engine, make requests, and receive responses from the server via AJAX. To learn more about these topics, see my article "How To Use AJAX." To follow along with the examples, you’ll need to download the source files. (You can also view a live sample.)

Getting Started

This article uses an AJAX engine that I created in order to abstract our AJAX requests and help us to share AJAX engine code between different applications. In order to use this engine, we simply import three JavaScript files and make requests to an object named AjaxUpdater. The engine will handle the rest, including delegating the response to the callback method specified in the request. Here’s an example of how we would make requests with this engine as well as import the associated files:

<script type="text/javascript" src="javascript/model/Ajax.js"></script>
<script type="text/javascript" src="javascript/model/HTTP.js"></script>
<script type="text/javascript" src="javascript/model/AjaxUpdater.js"></script>
<script type="text/javascript">
    document.load = AjaxUpdater.Update(’GET’, URL, callback);
</script>

Let’s get started by covering JavaScript objects.

  • Share ThisShare This
  • Your Account

Discussions

JSON JS Object serialization
Posted Mar 19, 2008 12:28 PM by sprash
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network