Dynamischer Webinhalt mit AHAHirgendwann 2007
Dynamischer Inhalt in Webseiten, wobei einfaches (X)HTML nachgeladen wird und in die Seite eingefügt wird.
Original von
http://microformats.org/wiki/rest/ahah.
Aufrufen mit function ahah(url, target).
function ahah(url, target) {
document.getElementById(target).innerHTML = ' Fetching data...';
ajax(url, function() {ahahDone(url, target);});
}
function ahahDone(url, target) {
if (req.readyState == 4) { // only if req is "loaded"
if (req.status == 200) { // only if "OK"
document.getElementById(target).innerHTML = req.responseText;
} else {
alert("An error occured:\n"+ req.status + "\n" +req.statusText+"\nPlease try again later!");
}
}
}
function ajax(url, func){
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = func;
req.open("GET", url, true);
req.send("");
}
}