Button Button Button Button

Back in summer, under the influence of AJAX craze I decided I wanted to add a bit of AJAX-like functionality and have the blog entries update without reloading the rest of the page. I looked at a few AJAX libraries, but found them too big and too complicated. Given that what I wanted was so simple, it just didn’t seem worth it. Then yesterday I read about AHAH, which is AJAX simplified to just two JavaScript functions, which did exactly what I wanted: make an HTTP call, get HTML from it and insert it into a div by ID. What I found surprising is how little it takes. The Javascript code (adapted from CrackAjax.net is here. It is just 45 lines, which included four lines that I had to write myself:

function getBlogEntry(path) {
   return callAHAH(
  "http://www.freewisdom.org/jatoba/blog_fragment.php?path=" + path, 
  "blog_entry", "<center>updating...</center>", "whoops");
}

After that, all I had to do is write a PHP script that returns requested page:

<?php
   $include_comments = '1';
   $comment_key = 'entries/' . $_GET['path'];
   include("/home/yuri/www/en/entries/" . $_GET['path'] . 
           "/fragment.html");
?>

I already had the text of each blog stored in a “fragment.html” in an appropriate directory, so all I had to do in this script is set a few parameters and include the file. With Ajax, you need to worry about getting the right headers, etc. Beyond that it is just a matter of adding “onclick="getBlogEntry(…); return false;” to the links.