Wednesday, June 21st, 2006 Enabling Data Exchange in Ajax Applications

Category: Ajax, Programming

On the Oracle Technology Network today, there’s a new tutorial that steps developers through the process of getting Ajax and their Java applications to play nicely together.

The Ajax core API known as XMLHttpRequest is all about sending HTTP requests for the sole purpose of exchanging data between Web browsers and servers. The JavaScript code running in a Web page can use XMLHttpRequest to submit the request parameters to a server-side script such as a Servlet or a JSP page. The invoked Servlet/JSP sends back a response containing data that is typically used to update the content viewed by the user without refreshing the whole page. This approach has both performance and usability advantages since the network traffic is reduced and the Web UI behaves almost like a desktop GUI.

In this article I’ll present the main methods for exchanging data between Ajax clients and servers, comparing the traditional Web application model with the Ajax model. I will also discuss techniques for handling and processing the data on both ends.

They start on the client side, building the requests correctly, including the encoding of the values to be dropped into the query. They drop those into an XML document and set up the other Javascript functionality to parse and serialize content with the DOM.

Next up, they give an example of sending a request (using a library created in a previous article) and include the functions to abort the request if needed, send a saved request, and send a request to the remote server for JSON to load.

From there, it’s a switch over to the server side of things. They talk about data validation functionality, including adding an error handler, and build up the code needed for an XMLSchema and DocumentBuilder object. They follow with the code to extract the information from the pased in XML, including fetching functions for different types of values. Lastly, they send back a response to the waiting client-side script, and give examples of both XML and JSON response types.

Posted by Chris Cornutt at 1:34 pm
1 Comment

4 rating from 50 votes

1 Comment »

Comments feed TrackBack URI

There is a nice function to parse and serialize a (xml) string and returns the DOM Document without useing innerHtml.

I didn0t know about DOMParser or XMLSerializer.

Comment by Joo — June 21, 2006

Leave a comment

You must be logged in to post a comment.