better late than never

There are all these AJAX libraries out there that help you add it to web apps, and that is great. However I am never one to use something without tearing off the hood and having a good look. So I decided that I wanted to make a simple webpage that updated itself with out a page reload. I figured that would be enough to put curiosity to rest on the subject. When you strip it all down, it’s not that hard to understand.

Some simple HTML:

Some simple JavaScript:

requestObject = new XMLHttpRequest();

function sendRequest() {
requestObject.open('get', 'http://localhost/cgi-bin/ajax.pl');
requestObject.onreadystatechange = handleResponse;
requestObject.send(null);
}

function handleResponse() {
if(requestObject.readyState == 4){
response = requestObject.responseText;
document.getElementById('thatDiv').innerHTML = response;
}
}

And a smattering of perl:

#!/usr/bin/perl -w
use strict;
use CGI;

my $q = new CGI;
my $text = $q->header();
$text .= "See I told you it was easy";

print $text;

…and well that is about it.

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in programming. Bookmark the permalink.

Comments are closed.