2 % $r->content_type('application/x-javascript');
4 // originally Fetched from http://www.opendarwin.org/~drernie/src/ahah.js - No Copyright - Public Domain
5 // a patch fetched from http://www.xfront.com/microformats/examples/ahah/example01/ahah.js - see http://issues.bestpractical.com/Ticket/Display.html?id=14296
7 function ahah(url, target, delay) {
8 // document.getElementById(target).innerHTML = 'Loading <a href="'+url+'">'+url +'</a>...';
10 if (window.XMLHttpRequest) {
11 req = new XMLHttpRequest();
12 } else if (window.ActiveXObject) {
13 req = new ActiveXObject("Microsoft.XMLHTTP");
17 if ( /webkit|firefox\/2/i.test( navigator.userAgent ) ) {
18 // seems safari has weird problem with post:
19 // it does remove the old content of target
20 // while doesn't replace that with new content
25 if (req != undefined) {
26 req.onreadystatechange = function() {ahahDone(req, url, target, delay);};
28 req.open("GET", url, true);
31 req.open("POST", url, true);
37 function ahahDone(req, url, target, delay) {
38 if (req.readyState == 4) { // only if req is "loaded"
39 if (req.status == 200) { // only if "OK"
40 document.getElementById(target).innerHTML = req.responseText;
42 document.getElementById(target).innerHTML="Error loading '"+url+"':\n"+req.statusText;
44 if (delay != undefined) {
45 setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
46 //server should ALSO delay before responding