AHAH!

AHAH = Asynchronous HTML and HTTP is a subset of AJAX without the X(XML)

  • Update web pages dynamically using JavaScript and XHTML, instead of XML.
  • Like in AJAX, use XMLHTTP to raise a Request.
  • The state-change of the request when the Response is received is directly passed on to a Function.
  • The response is directly fed into the intended target element (Div) of the document using the innerHTML attribute of elements.
  • Unlike AJAX, the response is not parsed at the client side.
  • Technically, its a subset of AJAX without the X (XML)
  • Works when you dont change the content structure of the XMLHTTP response.
  • Doesn’t work when you call HTML files with external .css and .js files.
  • Code is very simple (about 20 lines)
  • Was first used couple of years ago.

Sample Code to send a AHAH Request

function ahah(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = ‘sending…’;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ahahDone(target);};
req.open(“GET”, url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject(“Microsoft.XMLHTTP”);
if (req) {
req.onreadystatechange = function() {ahahDone(target);};
req.open(“GET”, url, true);
req.send();
}
}
}

Sample Code to receive a AHAH Request

function ahahDone(target) {
// only if req is “loaded”
if (req.readyState == 4) {
// only if “OK”
if (req.status == 200) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML=”ahah error:n” +
req.statusText;
}
}
}

Example

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s