| By Victor Rasputnis, Anatole Tartakovsky, Igor Nys | Article Rating: |
|
| February 19, 2006 05:45 PM EST | Reads: |
78,092 |
Our AJAX-enabled page is ready. The complete working example is available at: www.ajaxmaker.com:8080/blog/zipsearch.htm.
Remote Scripting - An Alternative Approach
Some older AJAX implementations are based on so-called remote scripting. The idea is that the user's actions result in querying the server via IFRAME, and the server responds with the JavaScript, which is immediately executed as soon as it reaches the client. This is a big difference compared to XMLHttpRequest approach, where the server responds with the data and the client interprets the data. The advantage is that this solution supports older browsers.
The HTML portion of the IFRAME-based example (see Listing 2) is similar to the one we've used in the XMLHTTPRequest scenario, but this time we'll introduce an extra IFRAME element - controller:
Zip:<input id="zipcode" type="text" maxlength="5" onKeyUp="zipChanged()"
style="width:60" size="20"/>
City: <input id="city" disabled maxlength="32" style="width:160" size="20"/>
State:<input id="state" disabled maxlength="2" style="width:30" size="20"/>
<iframe id="controller" style="visibility:hidden;width:0;height:0"></iframe>
We keep calling zipChanged() per every key stroke, but this time the function ask(), called from zipChanged() (see Listing 3), sets the IFRAME's src property, instead of invoking an XMLHTTPRequest:
function ask(url, fieldToFill, lookupField)
{
var controller = document.getElementById("controller");
controller.src = url+"&field="+fieldToFill.id+"&zip="+lookupField.id;
}
The server-side logic is presented by a sketchy resolveZip.jsp (see Listing 4). It's different from its XMLHTTPRequest counterpart in that it returns JavaScript statements, which set the global values of the variables field lookup and city and the call function response() from the global window's execution context as soon as it gets to the browser.
The function response() is a modified version of the handleResponse() which is absolved from dealing with uncompleted requests (see Listing 2.)
The Fine Print
For simplicity's sake, we've "overlooked" some important issues in our sample code:
1. The fact that the instances of the XMLHTTPRequest object and callback invocations haven't been destroyed after being used, which causes memory leaks after every call. Properly written code should destroy or reuse such instances in the object pool. Object management techniques common to the server software have to be used for the client
2. In quite a few places the errors weren't handled properly. For example, the call to request.open() in the method ask() can throw an exception that has to be caught and processed even though JavaScript exceptions don't have to be checked. The handleResponse() function is another example. It has to check headers and responseText for possible server-side and communication errors. In case of an error, it has to try to recover and/or report an error. Properly developed AJAX applications eliminate loosing data on "submissions" due to disconnects and other low-level communication problems via a robust, self-recovering framework.
3. Current server-side frameworks provide quite a few functions that have to be reconciled with a refresh-free approach. For example, let's consider a custom server-side authentication with a timeout. In that case we'd have to intercept security system response to the XMLHTTPRequest calls, bring up the login screen, and then re-issue the request after the user was authenticated.
All these problems are typical of any application code working with low-level APIs and all of them can be resolved. The good news is that the technologies needed to resolve these issues are quite familiar to most Java developers like Web Services, custom tags, and XML/XSLT. The only difference is that nowadays these technologies come to the rescue on the client in the form of:
- Web Services using SOAP/REST/RPC for a simple communication standard
- Client-side custom tags for packaging rich client-side controls with integrated AJAX functionality
- XML- and XSLT-based data manipulation
Summary
The AJAX approach offers a rich Internet experience on a par with that of desktop applications. AJAX features have to be applied selectively: you definitely don't want your credit card charged by the background process while you're still shopping. Is AJAX momentum sustainable? We certainly hope so. We've been developing AJAX applications for the last five years and can attest that it's sound and very effective. However, it requires that a developer be exposed to a much wider set of technologies than the ones used in the traditional "click-refresh" Web applications.
Published February 19, 2006 Reads 78,092
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Victor Rasputnis
Dr. Victor Rasputnis is a Managing Principal of Farata Systems. He's responsible for providing architectural design, implementation management and mentoring to companies migrating to XML Internet technologies. He holds a PhD in computer science from the Moscow Institute of Robotics. You can reach him at vrasputnis@faratasystems.com
More Stories By Anatole Tartakovsky
Anatole Tartakovsky is a Managing Principal of Farata Systems. He's responsible for creation of frameworks and reusable components. Anatole authored number of books and articles on AJAX, XML, Internet and client-server technologies. He holds an MS in mathematics. You can reach him at atartakovsky@faratasystems.com
More Stories By Igor Nys
Igor Nys is a Director of Technology Solutions at EPAM Systems, Inc, a company combining IT consulting expertise with advanced onshore-offshore software development practices. Igor has been working on many different computer platforms and languages including Java, C++, PowerBuilder, Lisp, Assembler since the mid 80's. Igor is currently managing a number of large distributed projects between US and Europe. In addition Igor is the author of the award-winning freeware system-management tools, and he was closely involved in the development of XMLSP technology - one of the AJAX pioneers.
![]() |
SYS-CON India News Desk 02/19/06 07:05:30 PM EST | |||
Browser-based applications are widely used and we like the fact that we can access them from anywhere. But from the users' perspective, the productivity level of Web applications still doesn't approximate the productivity of desktop programs. The good news is the gap is closing: the accumulated potential of multiple technologies has boosted a whole new breed of HTML-based apps that are as powerful as the desktop ones. Meet AJAX. |
||||
![]() |
Anatole Tartakovsky 12/26/05 06:15:32 PM EST | |||
I received number of questions on the future of the AJAX recently - tried to give my personal view on the possible development in the blog - http://anatolet.blogspot.com |
||||
![]() |
Frank 12/19/05 07:04:50 PM EST | |||
You mention the need to destroy the request and callback objects, but my O'Reilly reference says there is no need to clean up in javascript. Which is correct. How do you destroy the request and especially the callback objects (can I destroy the callback in the callback!!!)? |
||||
![]() |
Halans 10/15/05 06:25:27 PM EDT | |||
Nice, to the point, Ajax article. |
||||
![]() |
Victor Rasputnis 10/04/05 08:04:22 AM EDT | |||
Anand, you are right. The example was meant to be the most obvious, to avoid problems with getRealPath() or explanation around getResourseAsStream() etc. You have a good eye :), thanks again. |
||||
![]() |
Anand 10/03/05 01:42:54 PM EDT | |||
Thanks Victor. I had figured out application instead of using getServletContext() on BEA. However my problem was with the properties.load(new java.io.FileInputStream(key + ".property")); I had the file in the same folder and thought that I did not need to provide it with an explicit path such as c:\\ but I guess that is not the case. Also one more change to the html file that I figured in the line: should be zip.length == 3 ? updateState(zip) : zip.length == 5 ? updateCity(zip):""; |
||||
![]() |
Victor Rasputnis 09/30/05 10:31:34 PM EDT | |||
Anand, getServletContext() is available in Tomcat JSP, but not in WebLogic (WL -getServletConfig().getServletContext()). Anyway, I replaced gSC() to _application_ for simplicity. Please download again. Most importantly, please also download the DATA files or ZIP will remain red, no matter what :). Kind Regards, |
||||
![]() |
Anand 09/29/05 08:42:16 AM EDT | |||
I tried doing this sample using both IE 6 and Firefox. Everytime I type in 3 digits (valid zip code) it paints the box red. It does not populate the city and state. Using BEA I got an error on the JSP page saying that getServletContext() was not recognized. On Tomcat I did not get any error but the program won't work. |
||||
- 4th International Cloud Computing Conference & Expo Starts Today
- Publishing Synergy: Blog, Twitter and Ulitzer
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- Google Wave
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Can Revitalize Your Career as Software Developer
- SOA World Magazine "Readers' Choice Awards" Voting Is Now Open
- Oracle+MySQL Opponents Take to the Barricades
- Virtualization Expo Call for Papers Deadline December 15
- Oracle Faces Growing Price for MySQL
- SpringSource Moving to Spring 3.0
- 4th International Cloud Computing Conference & Expo Starts Today
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Publishing Synergy: Blog, Twitter and Ulitzer
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Google Wave
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Can Revitalize Your Career as Software Developer
- Oracle-Sun: IBM Reportedly Behind Delay
- Citrix Aims To Cripple VMware’s Cloud Designs
- Oracle Trashes HP Relationship for Sun
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- SCO CEO Posts Open Letter to the Open Source Community
- Simula Labs Launches Hosted Delivery Platform To Enable Enterprise Open Source Adoption
- Where Are RIA Technologies Headed in 2008?
- Source Claims SCO Will Sue Google
- How Open Is "Open"? – Industry Luminaries Join the Debate
- Latest SCO News is Plain Weird
- IBM Tells SCO Court It Can't Find AIX-on-Power Code
- SCO Claims Linux Lifted ELF
- Flashback: Investing in 'Professional Open Source' - Exclusive 2004 Interview with David Skok, Matrix Partners
- HP Starts Pushing Desktop Linux
- Linux Business Week Exclusive: Linux Kernel To Be Re-Written To Counter Microsoft FUD






























