2 % $r->content_type('application/x-javascript');
4 // Fetched from http://www.opendarwin.org/~drernie/src/ahah.js - No Copyright - Public Domain
5 function ahah(url, target, delay) {
6 // document.getElementById(target).innerHTML = 'Loading <a href="'+url+'">'+url +'</a>...';
7 if (window.XMLHttpRequest) {
8 req = new XMLHttpRequest();
9 } else if (window.ActiveXObject) {
10 req = new ActiveXObject("Microsoft.XMLHTTP");
14 if ( /webkit|firefox\/2/i.test( navigator.userAgent ) ) {
15 // seems safari has weird problem with post:
16 // it does remove the old content of target
17 // while doesn't replace that with new content
22 if (req != undefined) {
23 req.onreadystatechange = function() {ahahDone(url, target, delay);};
25 req.open("GET", url, true);
28 req.open("POST", url, true);
34 function ahahDone(url, target, delay) {
35 if (req.readyState == 4) { // only if req is "loaded"
36 if (req.status == 200) { // only if "OK"
37 document.getElementById(target).innerHTML = req.responseText;
39 document.getElementById(target).innerHTML="Error loading '"+url+"':\n"+req.statusText;
41 if (delay != undefined) {
42 setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
43 //server should ALSO delay before responding