代码:
// #############################################################################
// vB_AJAX_Handler
// #############################################################################
/**
* XML Sender Class
*
* @param boolean Should connections be asyncronous?
*/
function vB_AJAX_Handler(async)
{
/**
* Should connections be asynchronous?
*
* @var boolean
*/
this.async = async ? true : false;
}
// =============================================================================
// vB_AJAX_Handler methods
/**
* Initializes the XML handler
*
* @return boolean True if handler created OK
*/
vB_AJAX_Handler.prototype.init = function()
{
try
{
this.handler = new XMLHttpRequest();
return (this.handler.setRequestHeader ? true : false);
}
catch(e)
{
try
{
this.handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
return true;
}
catch(e)
{
return false;
}
}
}
/**
* Detects if the browser is fully compatible
*
* @return boolean
*/
vB_AJAX_Handler.prototype.is_compatible = function()
{
if (is_ie && !is_ie4) { return true; }
else if (XMLHttpRequest)
{
try { return XMLHttpRequest.prototype.setRequestHeader ? true : false; }
catch(e)
{
try { var tester = new XMLHttpRequest(); return tester.setRequestHeader ? true : false; }
catch(e) { return false; }
}
}
else { return false; }
}
/**
* Checks if the system is ready
*
* @return boolean False if ready
*/
vB_AJAX_Handler.prototype.not_ready = function()
{
return (this.handler.readyState && (this.handler.readyState < 4));
}
/**
* OnReadyStateChange event handler
*
* @param function
*/
vB_AJAX_Handler.prototype.onreadystatechange = function(event)
{
if (!this.handler)
{
if (!this.init())
{
return false;
}
}
if (typeof event == 'function')
{
this.handler.onreadystatechange = event;
}
else
{
alert('XML Sender OnReadyState event is not a function');
}
}
/**
* Sends data
*
* @param string Destination URL
* @param string Request Data
*
* @return mixed Return message
*/
vB_AJAX_Handler.prototype.send = function(desturl, datastream)
{
if (!this.handler)
{
if (!this.init())
{
return false;
}
}
if (!this.not_ready())
{
this.handler.open('POST', desturl, this.async);
this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.handler.send(datastream + '&s=' + fetch_sessionhash());
if (!this.async && this.handler.readyState == 4 && this.handler.status == 200)
{
return true;
}
}
return false;
}
// we can check this variable to see if browser is AJAX compatible
var AJAX_Compatible = vB_AJAX_Handler.prototype.is_compatible();
http://bbs.chinahtml.com/clientscrip...threadslist.js








vB 中的 AJAX 应用类








平板模式