aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes When not to use Ajax? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "When not to use Ajax?" Watch "When not to use Ajax?" New topic
Author

When not to use Ajax?

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi All

I am doing late hours in office because of AJAX. Well not exactly AJAX but becasue of the rendering of the page. So I wanted to know when to use Ajax.

This is my first AJAX module. I am using AJAX to render a data grid, basically a table inside a div. I thought it would be easy as I did a few simple excercises to get a feel. Well as far as AJAX's data fetching is concerned it's OK. The problem comes in when you need to render the response. The thing is you need to explicitly tell everything how it should be rendered. Rendering a whole table on fly is @#$@$@. Then as if it was not enough then you have different browser (mainly IE and non-IE) issues.

The good thing about it was that I learnt a lot about DOM. So does anyone has a list of do's and don'ts for AJAX usage?

And yeah as two posts won't let me win two books, appending a totally unrealated question here only .

How do I go about adding a checkbox through javascript with an onClick handler. One approach is to use the innerHTML property, and stuff in everything in there. Infact that's what I did but it didn't looked right to me. The whole table is rendered by using createElement so this innerHTML looks out of place. The other option was to use event handlers which sounded a bit scary.

[ April 12, 2007: Message edited by: Anupam Sinha ]
[ April 12, 2007: Message edited by: Anupam Sinha ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

Your first question is less a "when not to use Ajax" question, than a "how do I use Ajax effectively" question.

Have you considered using a JSP to format the table prior to sending it to the browser? I've used this tactic with great success.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Thanks for the reply Bear.

What we are doing is as follows:

The whole table is created on the fly. The table head can be one of the two forms. The table body is that part that needs to be data to be dynamically populated. Secondly the table also changes dynamically. I mean the head the no. cols. changes dynamically.
David C. Crane
author
Ranch Hand

Joined: Oct 13, 2005
Posts: 59
Hi Anupam,

Parsing XML documents on the client using DOM is no fun - I sympathise with you there.

You need structured data for the grid body, but if XML is causing problems, have you looked at JSON as an alternative? And, if you do decide to use XML, have you looked at XPath and XSLT as ways of simplifying the process? Chapter 2 deals with these issues, and gives examples of how XPath can take the pain out of XML handling.

Best,

Dave


---<br />Author of...<br />'Ajax in Action' <a href="http://manning.com/crane" target="_blank" rel="nofollow">http://manning.com/crane</a><br />'Prototype & Scriptaculous in Action'<br /><a href="http://manning.com/crane3" target="_blank" rel="nofollow">http://manning.com/crane3</a><br />'Ajax in Practice'<br /><a href="http://manning.com/crane2" target="_blank" rel="nofollow">http://manning.com/crane2</a>
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Dave

Thanks for the reply. The first thing after your reply I noticed was your signature. You seem to be quite an authority on AJAX. Well thanks for the sympathy. I have my whole team's sympathy with me. Yeah I was told about XSLT to take away some of the pain of rendering the HTML but then again it would be a new thing to learn. Probably in the long run it would be good but now I am trying to put my project back in schedule. Let's see what this saturday (being in office) brings in for me.

Don't realy know much about JSON. Probably would explore it in my spare time.
[ April 13, 2007: Message edited by: Anupam Sinha ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: When not to use Ajax?
 
Similar Threads
Returning JavaScript via Ajax
Icon for Javaranch
JSON, dynamically formatting, etc.
Displaying many rows in an html table.
Additional Java 2 certification exam