AJAX has actually revolutionized the user browsing experience and has made HTTP applications look sexier. Here, I’ll not get into the AJAX fundamentals; rather I’ll have some tips and tricks.
1. AJAX without XML:
AJAX stands for ‘A’synchronous ‘J’avaScript ‘A’nd ‘X’ML. So if XML is not in the application, it sounds weird! However, you need not have XML at all in your AJAX application.
Say you have a simple application to show the user names as and when the user types in the user name in te application form (so that he does not have go the round of request-response mechanism). In such a case, all you need to do is query the user name from the DB via the WebServer, get a YES or NO (= a Boolean value) and if it exists, then simply disable the signup button. There is no need to have the date embedded in XML. It will be an overkill!
Similarly whereever you think of not having an XML, you better stick to that approach as it will be more memory efficient. More on it in the subsequent tips.
2. AJAX with XML:
So, what the heck and what is the big deal – AJAX anyway comes with XML? Well, nothing - other than your choice of XML parser in the client side plays a crucial role. When you mine your XML response, you have to be very careful in choosing a parser, which is memory efficient.
There are many of them such as JDOM, DOM4J, SAX etc and recently of course StAX. Here SAX and StAX, without question, fit the bill.
3. AJAX with JSON:
As I said earlier, in AJAX application when you process XML elements, it is memory intensive. At the same time, XML, at the cost of being platform independent have its intelligence wrapped up insider elements (root, sub-elements etc) or attributes which are added to the core data.
To rescue, comes JSON. Here you not only need not have unnecessary elements wrapping up the core data, but also there is no need of cross browser coding (for MS-IE it will be different!). Because you have the built in “eval” function of Javascript doing the work for you.
4. AJAX without JavaScript:
Well, again it sounds weird! In fact, you need not use JS at all in your AJAX application. Say you are someone who is not very into JS programming and only bent on writing AJAX code. And you can vey well do that.
This can be done by another 3rd party software which is "AjaxAnywhere" project available on sourceforge. The concept is of a “zone”. A zone can be any HTML element with a division. Here the server side code such as Servlet or ASP calls the 'AAUtils.addZonesToRefresh()' method and this in turn gets intercepted by a filer (standard web filter) which converts the response to XML and the zone is updated!
5. AJAX Tags:
To develop AJAX tags is as straightforward as developing JSP tags. You need to extend the 'TagSupport' class in the JSP API and develop your XXX.tld file. This file will be finally be configured in deployment descriptor of your application.
There are many 3rd party Tag Libraries and you can use them as well for your benefit. However, if you need something specific to your need, you can very well develop them.
6. AJAX with Struts:
Struts is one of the most mature MVC frame-works and recently you have seen the emergence of Spring, Tapestry et al. Struts comes with many tag libraries and one of the tags that is AJAX enabled is Struts Layout. More specifically it has a suggestion area and you can set up the entire work with minimal coding. Or you can use you JS along with the Struts framework to build an AJAX application.
The only difference here is you have action classes (such as SuggestAction) in place of Servlets which will be processing your requests. Similarly, for other MVC frameworks, you can have the AJAX phenom.
7. AJAX Debugging:
AJAX can be debugged with Google WebToolkit along with an IDE such as Eclipse. The key here is code will be completely in Java (your client code, JS code, HTML code) in hosted mode and it will can be run in a compact tomcat available in the Toolkit. Once you have complied the code is segregated, i.e., you will get your JS code and HTML code.
Welcome Chrome – the new browser from Google! I have checked the JS Debugger in Chrome and it seems to be better than the existing ones - such as Mozilla, Firefox or Opera. There are other standalone JS debuggers, but Chrome seems to have a different take. More of it sometime later - how to debug using Chrome.
For our services, please visit:
http://www.teleox.com/
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment