Hacker News new | past | comments | ask | show | jobs | submit login
[Ask YC] AJAX vs. AHAH
5 points by senthil_rajasek on June 14, 2008 | hide | past | favorite | 11 comments
I have been struggling with this question so I thought I would ask YC.

Personally, I am leaning more towards AHAH.




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.


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!


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.


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).


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.


What's wrong with using innerHTML?


Primarily, memory leaks

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


Several bugs and issues, some things don't work, issues with tables...

Not to mention the fact it just looks ugly and horrible IMHO.

Setting innerHTML to a string, in order to deserialize a partial HTML fragment is just not nice.

The DOM methods are actually pretty well thought out, and provide a far better interface to manipulate the document.


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

Anyway, I prefer using JSON for most things.


[deleted]


AHAH is Asynchronous HTML and HTTP. This is where you send html chunks instead of XML or JSON.


I should have done some research first.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: