Ajax Code Posted by John Wehr05/15/2005 10:07:01 PM
This code was posted in a response to this post.
XMLHttpRequests = new Array();
XMLHttpRequest_callbacks = new Array();
XMLHttpRequest_count = 0;
function runcallback(i) {
if (XMLHttpRequests[i].readyState == 4) {
if( self[ XMLHttpRequest_callbacks[i] ] ) {
self[ XMLHttpRequest_callbacks[i] ]( XMLHttpRequests[i].responseXML );
} else {
eval('f = function() { runcallback(' + i + '); }');
setTimeout( f, 100 );
}
XMLHttpRequest_count -= 1;
}
}
function loadXMLDoc( url, c, postvars ) {
if (window.XMLHttpRequest) {
XMLHttpRequests.push( new XMLHttpRequest() );
} else if (window.ActiveXObject) {
XMLHttpRequests.push( new ActiveXObject('Microsoft.XMLHTTP') );
}
XMLHttpRequest_callbacks.push( c );
i = XMLHttpRequests.length - 1;
eval('f = function() { runcallback(' + i + '); }');
XMLHttpRequests[i].onreadystatechange = f;
if( !postvars ) {
XMLHttpRequests[i].open('GET', url, true);
XMLHttpRequests[i].send( null );
} else {
pv = "";
for( key in postvars ) {
pv += '&' + key + '=' + postvars[key];
}
XMLHttpRequests[i].open('POST', url, true);
XMLHttpRequests[i].send( pv.substring(1) );
}
XMLHttpRequest_count += 1;
}
function handler( xml ) {
////
}
/*
Then do something like
loadXMLDoc('rest.php?mode=info', 'handler' );
*/

the hitchhiker's guide to anti-spam for Lotus Domino
- 











