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' );


*/
Never Underestimate The Power Of The Schwartz
Yellow Is The New Black
Don't Panic Links
Contact Me
CloseSidebars.gif
Story Calendar
August 2008
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
12
13
14
15
16
17
18
19
20
22
23
24
25
26
27
28
29
30
31
Lotus Domino ND6 RSS News Feed RSS Comments Feed Blog Admin Lotus Geek OpenNTF BlogSphere
Monthly Archive
Stories By Category
Responses Elsewhere
Life, The Universe, And Everything Else