[cgiapp] Ajax app using CAP -- return JSON or HTML?

Stewart Heckenberg stewart.heckenberg at gmail.com
Sat May 24 23:58:34 EDT 2008


> I'm at a crossroad:
> should the CAP-based back-end normally return
>  JSON data (and let the javascript library (I've decided on jQuery)
> place and format the data on the page),
> or should the back-end normally return
>  HTML (via html templates), which will be dropped into different, say, <div>s?
> (BTW, I'm not considering XML.)

Depends mostly on what the application you're writing does. One way of
doing it is to write the whole thing sans-ajax, e.g. have a runmode
that returns only a form and another that returns only the results of
that form, and then you can easily convert that to ajax with jQuery by
doing what you suggest above, i.e. loading the form results into a div
(done by using jQuery to catch the form submission and call the
results runmode via ajax). I wouldn't pass the data back as JSON
unless it's some instance where that data is more useful in that
format, e.g. using it with jQuery or some other JavaScript API to do
something funky.


More information about the cgiapp mailing list