views:

205

answers:

3

I have a classic ASP application

I would like to add some AJAX-style partial page updates to avoid server roundtrip. For example, list of rows displayed, option to add another in-situ, save it, and table redisplayed / add another.

I don't think I need all the other baggage of the well known AJAX libraries

I would appreciate suggestions for AJAH libraries, and also opinions on whether you think I am daft only adopting AJAH rather than full blown AJAX.

(My application has a template rendering function, so I can already convert database data into "rich HTML", so I perceive that my easiest route is to reuse this and send replacement HTML, using AJAH, to be injected into the page using innerHTML replace)

Thanks

+3  A: 

AJAH? There is to my knowledge no such thing as AJAH. Does the H stand for HTML instead of XML? If so, let me disabuse you of the notion that AJAX entails XML. That may have been its inception but that is not the case (now at least). In the moern vernacular Ajax has come to mean pages making Javascript calls back to the server without refreshing the page. Data can be sent to the server and the data returned can be JSON, XML, HTML or whatever you like really. JSON and HTML are probably the most common (with XML next).

As for what API to use. It sounds like you want to spruce up an existing application and (imho) there is no better library for this than jQuery. Its as lightweight as you want with plugins for almost everything and helps you a lot with cross-browser issues. You can easily do things like:

<input id="refresh" type="button" value="Refresh">
...
$("#refresh").click(function() {
  $.ajax({
    url: '/getusers',
    type: "GET",
    timeout: 5000,
    dataType: "html",
    failure: function() {
      alert("An error occurred.");
    },
    success: function(data) {
      $("#userlist").html(data);
    }
  });
});
cletus
A: 

Link to a quick explanation of the AJAH pattern here: "Asynchronous JavaScript and HTML (Ajah) is a pattern whereby you pass back fully rendered HTML responses rather than XML or JSON formats".

It does appear to blur the lines between the model and the view part of your application (a big sin if you are a MVC purist!), but it sounds like it will produce working software..

IMHO the overhead of a good javascript library (like jQuery) is not that big either, and you usually end up needing one anyway.

Kristian
+1  A: 

i hate to be a purist; but i think that once you start to use AJAX, it's far better to let the JS code to do most of the formatting. for your example (tables), i'd use a templating plugin for jQuery. these let you include a static HTML template in the page, and fill it with the data returned by the AJAX queries.

OTOH, if you really want to do the formatting in the server, simply use the .load() method in jQuery to fetch HTML and insert into any DOM object.

Javier
I often find it easier to use rendered HTML results simply because I can reuse part of my script that created the page in the first place rather than also doing to templating in Javascript as well. It's a bit like unnecessary repetition.
cletus
"i'd use a templating plugin for jQuery" - is that jTemplate, or are there others? The feature-set of jTemplate falls a long way short of what we currently can do with our server-side template rendering; I'd be very happy to consider other, richer, client-side template rendering tools
Kristen
just browsing the plugins page: jBind, jsRepeater, jTemplates, Orange, noTemplate, SuperFlyDom, Template, or even some XSLT engines. i like noTemplate approach, but usually even JS's .replace() method fits the bill. a template language shouldn't be Turing-complete, that's what JS is for!
Javier
Had a look at those, thanks. Here's a link for anyone else wanting to see tools for handling Templates in JQuery: http://plugins.jquery.com/taxonomy/term/296 and the Layout category: http://plugins.jquery.com/project/Plugins/category/51
Kristen
@Javier: I've had a good look at them, and they are short of the functionality we currently have. Still rather undecided! its a big step to choose a comprehensive AJAX library, but I've been watching YUI, JQuery, Prototype over many months. Time to build reasonably comprehensive prototypes I think
Kristen
OK, I've been on a further trawl (for the last couple of days ...) JQuery is well liked in this community, and my worries about AJAX have been allayed. I might be better off changing my server-side template render to send formed/cached javascript merge script + data to be rendered at client
Kristen