I am just adding this for my own reference this is an Ajax Engine that I wrote a while ago.
function Ajaxengine(){
};
Ajaxengine.loadStatus=false;
Ajaxengine.loadDoc = function (url, sMethod, method, params, msg){
try{
try { xmlhttp = new ActiveXObject(
"Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject(
"Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if(!Ajaxengine.loadStatus){
if(msg){
Ajaxengine.addMessage(msg);
}
Ajaxengine.loadStatus=true;
call = new Object();
call.method=method;
call.xmlhttp=xmlhttp;
var urlParams=null;
for (var element in params){
temp=params[element];
temp=temp.split(
":");
if(!urlParams){
urlParams=temp[0] +
"=" + temp[1];
}else{
urlParams=urlParams +
"&" + temp[0] +
"=" + temp[1];
}
}
urlParams = encodeURI(urlParams);
temp=
"";
/* branch for native XMLHttpRequest object*/ sURL=url + '?' + urlParams
if (sMethod ==
"GET"){
call.xmlhttp.open(sMethod, sURL, true);
sVars =
"";
}else {
call.xmlhttp.open(sMethod, sURL, true);
call.xmlhttp.setRequestHeader(
"Method",
"POST "+sURL+
" HTTP/1.1");
call.xmlhttp.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded");
}
call.xmlhttp.onreadystatechange = function() { Ajaxengine._Change(call); };
call.xmlhttp.send(urlParams);
}
}catch(oException) {
alert(
"Got the following expection data (1): " + oException);
}
};
Ajaxengine._Change = function (call) {
try{
if (call.xmlhttp.readyState == 4) {
var txt=null;
txt=call.xmlhttp.responseText;
call.method(txt);
Ajaxengine.loadStatus=false;
Ajaxengine.removeMessage();
if (call.xmlhttp.status == 200) {
return true;
} else {
return false;
alert(
"There was a problem retrieving the XML data:\n" + call.req.statusText);
}
}
}catch(oException) {
alert(
"Got the following expection data: _change " + oException);
}
}
Ajaxengine.addMessage = function (msg){
var _message=getEL(
"messagebox");
if(_message){
document.body.removeChild(_message);
return false;
}
var _messageSpanShell = document.createElement(
"span");
_messageSpanShell.id =
"messagebox";
_messageSpanShell.className=
"messagebox";
_messageSpanShell.innerHTML=msg;
document.body.appendChild(_messageSpanShell);
}
Ajaxengine.removeMessage = function (){
var _message=getEL(
"messagebox");
if(_message){
document.body.removeChild(_message);
return false;
}
}