Ajax Framework Code by Richard Schwartz10/18/2005 12:14:32 AM

function initXMLHttpRequest() {
   // branch for native XMLHttpRequest object
   if (window.XMLHttpRequest) {

      req = new XMLHttpRequest();
      }
   else if (window.ActiveXObject) {

      // branch for IE/Windows ActiveX version
      req = new ActiveXObject("Microsoft.XMLHTTP");
      }

   return(req);
   }
function makeCustomHandlerForObject(reqString, targetObjectString, returnProperty) {

   out = "var xmlOutput = processReadyStateChange(window[\"" + reqString + "\"],\"" + 
             returnProperty + "\");";
   out = out + "if ( ! (typeof(xmlOutput) == \"string\" && xmlOutput == \"\") ) {"+
             targetObjectString + "= xmlOutput; window[\"" + reqString + "\"] = null;}";

   return out;
   }
function makeCustomHandlerForFunction(reqString, targetObjectString, returnProperty) {

   out = "var xmlOutput = processReadyStateChange(window[\"" + reqString + "\"],\"" + 
             returnProperty + "\");"
   out = out + "if ( ! (typeof(xmlOutput) == \"string\" && xmlOutput == \"\") ) {" + 
             targetObjectString.substr(0, targetObjectString.length - 1) + 
             ",xmlOutput); window[\"" + reqString + "\"] = null;}";

   return out;
   }
function loadXMLDoc(url, reqIndex, target, property) {

   req = window[  reqIndex ];
   if (target.substr(target.length - 1, 1) == ")") {

      req.onreadystatechange = new Function( makeCustomHandlerForFunction(reqIndex, target, property) );

      }
   else {
      req.onreadystatechange = new Function( makeCustomHandlerForObject(reqIndex, target, property) );

      }
   req.open("GET", url, true;

   if (window.XMLHttpRequest) {
      req.send(null;

      }
   else {
      req.send();
      }

   }
function processReadyStateChange(req, property) {
   // only if req shows "complete"

   if (req.readyState == 4) {
      // only if "OK"

      if (req.status == 200) {
         return req[ property ];

         }
      else {
         alert("There was a problem retrieving the RSS feed\n" + req.statusText) }

      }
   return "";
   }
var reqNum = 0;

function getXMLText(source, target) {
   var reqIndex = "req" + (++reqNum);

   window[ reqIndex ] = initXMLHttpRequest();
   loadXMLDoc(source, reqIndex, target, "responseText")}

function getXMLDoc(source, target) {
   var reqIndex = "req" + (++reqNum);

   window[ reqIndex ] = initXMLHttpRequest();
   loadXMLDoc(source, reqIndex, target, "responseXML")}

function getFirstElement(node, elementName) {
   child = node.firstChild;

   while ( child != null ) {
      if (child.nodeType == 1) {

         if ( child.nodeName == elementName) {
            return child;

            }
         }
      child = child.nextSibling;
      }

   return null;
   }
function getLastElement(node, elementName) {

   child = node.lastChild;
   while ( child != null ) {

      if (child.nodeType == 1) {
         if ( child.nodeName == elementName) {

            return child;
            }
         }
      child = child.previousSibling;

      }
   return null;
   }
function getNthElement(node, elementName, n) {

   foundCount = 0;
   child = node.firstChild;
   while (child != null {

      if (child.nodeType == 1) {
         if (child.nodeName == elementName) {

            foundCount = foundCount + 1;
            if (foundCount == n) {

               return child;
               }
            }
         }
      child = child.nextSibling }

   return null;
   }
function getElementText(node) {

   if (node == null {
      return("");

      }
   child = node.firstChild;
   foundCDATA = false;

   foundPlainText = false;
   while (child != null {

      if (child.nodeType == 4) {
         // CDATA node

         result = child.nodeValue;
         foundCDATA = true;
         }

      else {
         if (child.nodeType == 3) {

            // Text node
            result = child.nodeValue;
            foundPlainText = true;

            }
         }
      if (foundCDATA == true {

         return result }
      child = child.nextSibling }
   if (foundPlainText == false {

      return("") }
   return result;
   }


Never Underestimate The Power Of The Schwartz
Yellow Is The New Black
Don't Panic Links
Contact Me
CloseSidebars.gif
Story Calendar
September 2008
Su
Mo
Tu
We
Th
Fr
Sa
2
3
5
6
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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