ajax = Class.create();
ajax.prototype =
{
initialize: function(url, options, loadingMessage)
{
this.transport = this.getTransport();
this.postBody = options.postBody || '';
this.method = options.method || 'post';
this.onComplete = $(options.onComplete) || null;
this.loadingMessage = loadingMessage;
this.update = $(options.update) || null;
this.request(url);
},
request: function(url)
{
if(this.loadingMessage != '')
{
this.update.innerHTML = '

'+this.loadingMessage+'
';
}
this.transport.open(this.method, url, true);
this.transport.onreadystatechange = this.onStateChange.bind(this);
if (this.method == 'post')
{
this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
if (this.transport.overrideMimeType)
{
this.transport.setRequestHeader('Connection', 'close');
}
}
this.transport.send(this.postBody);
},
onStateChange: function()
{
if (this.transport.readyState == 4 && this.transport.status == 200)
{
if (this.onComplete)
{
setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
}
if (this.update)
{
setTimeout(function(){this.update.innerHTML = this.transport.responseText; execJs(this.update);}.bind(this), 10);
}
this.transport.onreadystatechange = function(){};
}
},
getTransport: function()
{
if (window.ActiveXObject)
{
return new ActiveXObject('Microsoft.XMLHTTP');
}
else if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else
{
return false;
}
}
};