Awright, a couple issues with it - sorry I was going fast and I thought that you'd be able to debug it if there were troubles.
The 2 biggest troubles - I hope you added a source line to pull down the ajaxRequestor class so that it was available to the page - in my example I don't reference it anywhere.

Second, it seems that the forum software adds text gremlins to the source, so if you just copy/paste and try to run it you may get immediate and really weird troubles. In BBE or TextWrangler, select Text/Zap Gremlins to get rid of the weirdness. In other editors you could probably say, "Show Invisibles" and you'll see what I mean.
Here is code that is just slightly tweaked for better effect. It 100% works. Also at the bottom is a reprint of the ajaxRequestor class just for good measure - and another little ditty, dumpArray() which I use for debugging that you can play with. It's pretty handy.
The main html page:
<html>
<head>
<script src="/class.ajaxRequestor.js"></script>
<style>
#resultBox {
height: 300px;
width: 500px;
margin: 0 auto;
margin-top: 20px;
border-color: black;
border-style: solid;
border-width: 1px 2px 2px 1px;
background-color: #a0a0a0;
}
#selectType {
margin-right: 20px;
}
</style>
</head>
<body>
<div style="text-align: center">
<select id="selectType">
<option value="0">Simple Update</option>
<option value="1">JSON Array</option>
<option value="2">Javascript Redirect</option>
<option value="3">Preformatted HTML</option>
</select>
<input id="testbutton" type="button" value="Test" onClick="test()">
</div>
<div id="resultBox" style=""> </div>
<script>
req = new ajaxRequestor();
req.url = '/handler.php';
resArr = new Array();
function test()
{
var target = document.getElementById('selectType');
var which = target.options[target.selectedIndex].value - 0;
req.postParam('request', which);
switch(which)
{
case 0:
// This option will hide the test button..
hideButton();
req.onSuccess = function(sender) { showButton(); document.getElementById('resultBox').innerHTML = 'Response received: ' + sender.lastResponse; }
break;
case 1:
// This one too.
hideButton();
req.onSuccess = handleJSON;
break;
case 2:
req.onSuccess = function(sender) { eval(sender.lastResponse); }
break;
case 3:
req.onSuccess = function(sender) { document.getElementById('resultBox').innerHTML = sender.lastResponse; }
break;
}
req.execute();
}
function hideButton()
{
document.getElementById('testbutton').style.display = 'none';
}
function showButton()
{
document.getElementById('testbutton').style.display = 'inline';
}
function handleJSON(sender)
{
showButton();
try
{
resArr = eval('(' + sender.lastResponse + ')');
document.getElementById('resultBox').innerHTML = dumpArray(resArr);
} catch(e) {
alert('Result from server was not valid JSON code. Response was: ' + sender.lastResponse);
}
}
</script>
</body>
</html>
Meanwhile at the server,
handler.php:
<?php
$reqType=$_POST['request']-0;
switch($reqType)
{
case 0:
die('OK: ' . date('H:i:s', time()));
case 1:
$newArr['a']=1234;
$newArr['b']=2345;
$newArr['c']=3456;
$arrStr = json_encode($newArr);
echo $arrStr;
break;
case 2:
echo"top.location='http://www.google.com/';";
exit;
case 3:
echo<<<HTML
<center>
<h1>Hello World!</h1>
<h3>Four score and seven years ago, our fathers brought forth<br>
to this country - a new nation - conceived in liberty and dedicated<br>
to the proposition that all men are created equal.<br><br>
Or something like that.
</h3>
HTML;
break;
}
?>
And finally, at the server, the source for
class.ajaxRequestor.js:
function dumpArray(arr, level)
{
var dumped_text = "";
if (!level) { level = 0; }
// The padding given at the beginning of the line.
var level_padding = "";
for (var j=0; j<level; j++) { level_padding += ' '; }
if (typeof(arr) == 'object')
{
// Array, Hashes & Objects
for (var item in arr)
{
var value = arr[item];
if (typeof(value) == 'object')
{
// If it is an array...
dumped_text += level_padding + "['" + item + "']\n";
dumped_text += dumpArray(value,level+1);
} else {
vSurround = (typeof(value) == 'string') ? "'" : '';
nSurround = (item.match(/^[0-9]{1,10}$/)) ? '' : "'";
dumped_text += level_padding + "[" + nSurround + item + nSurround + "] => " + vSurround + value + vSurround + "\n";
}
}
} else {
// Stings, Chars & Numbers etc.
dumped_text = "(" + typeof(arr) + ") " + arr + "\n";
}
return dumped_text;
}
// ----------------------------------------------------------- //
// ajaxRequestor //
// ----------------------------------------------------------- //
function ajaxRequestor() { this.clearAll(); }
ajaxRequestor.prototype.__defaultError = function(sender)
{
var tempStr = "ajaxRequestor Error:\n" +
"status: " + this.requestor.status + "\n" +
"headers: " + this.requestor.getAllResponseHeaders();
alert(tempStr);
}
ajaxRequestor.prototype.__defaultSuccess = function(sender)
{
alert("ajaxRequestor successfully returned from a request - but there is no handler assigned to receive it");
}
ajaxRequestor.prototype.__decodeString = function(inputStr)
{
var decoded = unescape(inputStr);
decoded = decoded.replace(/\%2F/g, "/");
decoded = decoded.replace(/\%3F/g, "?");
decoded = decoded.replace(/\%3D/g, "=");
decoded = decoded.replace(/\%26/g, "&");
decoded = decoded.replace(/\%40/g, "@");
return decoded;
}
ajaxRequestor.prototype.__encodeString = function(inputStr)
{
var encoded = escape(inputStr);
encoded = encoded.replace(/\//g,"%2F");
encoded = encoded.replace(/\?/g,"%3F");
encoded = encoded.replace(/=/g,"%3D");
encoded = encoded.replace(/&/g,"%26");
encoded = encoded.replace(/@/g,"%40");
return encoded;
}
ajaxRequestor.prototype.__getParams = function()
{
if (this.getNames.length == 0) { return ""; }
var out = (this.url.indexOf('?') == -1) ? '?' : '&';
for (var i=0; i<this.getNames.length; i++)
{
out += this.getNames[i] + '=' + this.getValues[i];
if (i < (this.getNames.length - 1)) { out += '&'; }
}
return out;
}
ajaxRequestor.prototype.__getRequestor = function()
{
if ((this.requestor != null) && (!this.reqIsIE)) { return true; }
try {
this.requestor = new XMLHttpRequest();
this.reqIsIE = false;
return; true;
} catch(e) {}
try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP.6.0");
this.reqIsIE = true;
return; true;
} catch(e) {}
try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP.3.0");
this.reqIsIE = true;
return; true;
} catch(e) {}
try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP");
this.reqIsIE = true;
return; true;
} catch(e) {}
try {
this.requestor = new ActiveXObject("Microsoft.XMLHTTP");
this.reqIsIE = true;
return; true;
} catch(e) {}
alert('ajaxRequestor Fatal Error: Cannot instantiate an XMLHTTP Object');
}
ajaxRequestor.prototype.__xmitLog = function(theMsg)
{
var bodyArr = document.getElementsByTagName('body');
var theBody = bodyArr[0];
theBody.appendChild(document.createTextNode(theMsg));
theBody.appendChild(document.createElement('br'));
}
ajaxRequestor.prototype.__onRTS = function()
{
if ((this.requestor.readyState >= 2) && (this.timeoutHandle))
{
clearTimeout(this.timeoutHandle);
this.timeoutHandle = false;
}
if (this.requestor.readyState == 4)
{
if (this.masterStatus) { this.masterStatus.handleChange(false); }
if ((this.requestor.status==200) || (this.requestor.status==0))
{
this.lastResponse = this.__decodeString(this.requestor.responseText);
if (!this.lastResponse)
{
return false;
}
if (this.xmlHandler)
{
this.xmlHandler.importXML(this.lastResponse);
}
this.onSuccess(this);
} else {
switch(this.requestor.status)
{
case 12029:
case 12030:
case 12031:
case 12152:
case 12159:
alert('Untrapped error: ' + this.request.status);
/*
var loader = this;
setTimeout( function() { loader.execute.call(loader); }, 10);
*/
break;
default:
this.onError(this);
}
}
this.busy = false;
}
}
ajaxRequestor.prototype.__postParams = function()
{
var out = "";
var varNames = '';
for (var i=0; i<this.postNames.length; i++)
{
if (i > 0) { varNames += '|'; }
varNames += this.postNames[i];
if (i > 0) { out += '&'; }
out += this.postNames[i] + '=' + this.__encodeString(this.postValues[i]);
}
if (out) { out += '&' + 'ajax_var_names=' + varNames; }
return out;
}
ajaxRequestor.prototype.abort = function()
{
if (this.busy)
{
// clear timeout as well
this.requestor.abort();
clearTimeout(this.timeoutHandle);
this.timeoutHandle = false;
this.busy = false;
}
}
ajaxRequestor.prototype.clear = function()
{
this.methodPost = true;
this.__transStatus = 0;
this.__transBusy = false;
this.lastResponse = new String();
this.selfReference = null;
this.newRequest();
this.timeoutHandle = false;
this.timeoutMS = 5000;
}
ajaxRequestor.prototype.clearAll = function()
{
this.xmlHandler = null;
this.masterStatus = null;
this.onUnrecognized = new String();
this.onError = this.__defaultError;
this.onSuccess = this.__defaultSuccess;
this.clear();
}
ajaxRequestor.prototype.execute = function(timeoutVal)
{
if (this.busy)
{
// clear timeout as well
this.requestor.abort();
this.busy = false;
}
var thisTimeoutVal = this.timeoutMS;
if (timeoutVal != undefined) { thisTimeoutVal = timeoutVal; }
this.__getRequestor();
if (!this.requestor) {
alert("You cannot dispatch a request on this machine (no viable XMLHTTPRequestor)");
return "";
}
if (!this.url) {
alert("You must supply a URL to ajaxRequestor to process a request");
return "";
}
this.busy = true;
var httpMethod = (this.methodPost) ? 'POST' : 'GET';
var theURL = this.url;
theURL += this.__getParams();
this.lastRequest = theURL;
var loader = this;
this.requestor.onreadystatechange = function() { loader.__onRTS.call(loader); }
if (this.masterStatus) { this.masterStatus.handleChange(true); }
// Set a callback to <me> in case the request takes to long...
this.timeoutHandle = setTimeout( function() { loader.__handleTimeout.call(loader); }, this.timeoutMS);
this.requestor.open('POST', theURL, true);
this.requestor.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if ((document.all) && (document.getElementById))
{
// IE
setTimeout( function() { loader.__executeSend.call(loader) }, 10);
} else {
this.requestor.send(this.__postParams());
}
}
ajaxRequestor.prototype.__executeSend = function() { this.requestor.send(this.__postParams()); }
ajaxRequestor.prototype.__handleAbort = function()
{
if (this.masterStatus) { this.masterStatus.handleChange(false); }
this.requestor.abort();
}
ajaxRequestor.prototype.__handleTimeout = function()
{
this.__handleAbort();
var loader = this;
setTimeout(function() { loader.execute.call(loader); }, 100);
}
ajaxRequestor.prototype.getParam = function(key, value)
{
var ptr = this.getNames.length;
for (var i=0; i<this.getNames.length; i++)
{
if (this.getNames[i] == key) { ptr = i; }
}
this.getNames[ptr] = key;
this.getValues[ptr] = value;
}
ajaxRequestor.prototype.method = function(doPost)
{
this.methodPost = (doPost);
}
ajaxRequestor.prototype.newRequest = function()
{
this.getNames = new Array();
this.getValues = new Array();
this.postNames = new Array();
this.postValues = new Array();
this.url = '';
}
ajaxRequestor.prototype.postParam = function(key, value)
{
var ptr = this.postNames.length;
for (var i=0; i<this.postNames.length; i++)
{
if (this.postNames[i] == key) { ptr = i; }
}
this.postNames[ptr] = key;
this.postValues[ptr] = value;
}