

[Ask YC] AJAX vs. AHAH - senthil_rajasek

I have been struggling with this question so I thought I would ask YC.<p>Personally, I am leaning more towards AHAH.
======
martythemaniak
I am partial to AJAJ myself.

0\. Sending back JSON allows you to to generate HTML just as easily on the
client-side as it does on the server. 1\. Makes your backend more generic by
default, so makes it easier for other apps to use your service (JSON is
included in many languages these days) 2\. Makes your design a whole lot
cleaner 3\. Is (generally) less work than dealing with full XML.

------
sh1mmer
JSON or FJSON (a JSON object wrapped in a function) would be my preferred
solution. Either via script hacks or XHR. The Y! APIs mostly support FJSON.

An important thing to avoid with AHAH for example is not having sites that
progressively enhance. If you get used to throwing whole chunks of markup into
the page it's easy to forget people who aren't able to use your dynamic page
loading solution.

Some kind of JSON will also allow you to get a status on the information that
you got back from the server. While you could do this HTTP status codes it
would be a lot harder to do x-browser especially if you are using a library to
do your AJAX/script inclusion.

If you have status codes it allows you to do more complex operations, such as
highlighting in red the parts of a form field that weren't completed. If you
have to replace the whole form is would be pretty inefficient.

DISCLAIMER: I work for Y!

------
simonw
It Depends. If you're doing something really simple where you know exactly
what the HTML you're slotting in to the DOM is going to look like, go with
AHAH - it's generally easier to generate HTML snippets on the server-side than
the client-side due to JavaScript's poor support for multi-line strings.

If you're likely to want to re-use the data service you're building in more
than one place, go with JSON. The problem with an AHAH endpoint is that it can
only be used for one thing - a JSON endpoint can easily be repurposed for
other parts of your application.

The only reason to bother with XML is if you're going to be doing HUGE
transforms of e.g. a ton of data in to an HTML table, at which point you might
want to use client-side XSLT for a speed boost. The vast majority of
applications won't need that though, in which case JSON is far more
convenient.

------
twism
they both have their pros and cons. I would rather send JSON as opposed to
XML, its easier to work with client side and smaller response size, but HTML
is easiest to work with client side and could be made to work when javascript
is turned off (at the expense of server cpu cycles transforming the data to
html before sending it).

------
axod
JSON is better IMHO. HTML is pretty ugly and using innerHTML is an extremely
bad idea. Better to send data as JSON, and manipulate the DOM if you need.

~~~
simonw
What's wrong with using innerHTML?

~~~
senthil_rajasek
Primarily, memory leaks

You can find better reasons here <http://ajaxian.com/archives/the-problem-
with-innerhtml>

------
tlrobinson
Shouldn't it be called AJAH? It still requires JavaScript...

Anyway, I prefer using JSON for most things.

