Reviewing myAHAHlib.js

Listing 17.1 shows the code of myAHAHlib.js, reproduced from Lesson 13.

Listing 17.1. myAHAHlib.js

 

 

function callAHAH(url, pageElement, callMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");
       /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");
         /* some versions IE */
         } catch (E) {
          req = false;
         }
       }
     }
     req.onreadystatechange = function() {responseAHAH(pageElement);};
     req.open("GET",url,true);
     req.send(null);
  }
function responseAHAH(pageElement) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
         }
      }
  }

 

Let's consider how we may extend the capabilities of this library: