Silki
view release on metacpan or search on metacpan
share/js-source/HTTP/Request.js view on Meta::CPAN
this.transport.setRequestHeader( "Connection", "close" );
}
}
/* TODO Add support for this back in later
if (this.options.requestHeaders)
requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
*/
};
// XXX This confuses me a little ... how are undefined and 0 considered a success?
HTTP.Request.prototype.isSuccess = function () {
return this.transport.status == undefined
|| this.transport.status == 0
|| (this.transport.status >= 200 && this.transport.status < 300);
};
HTTP.Request.prototype.onStateChange = function() {
var readyState = this.transport.readyState;
if (readyState != 1) {
this.respondToReadyState( this.transport.readyState );
}
};
HTTP.Request.prototype.respondToReadyState = function( readyState ) {
var event = HTTP.Request.EventNames[readyState];
if (event == "complete") {
var func = this.getOption( "on" + this.transport.status );
if ( ! func ) {
if ( this.isSuccess() ) {
func = this.getOption( "onsuccess" );
}
else {
func = this.getOption( "onfailure" );
}
}
if ( func ) {
( func )( this.transport );
}
}
if ( this.getOption( "on" + event ) )
( this.getOption( "on" + event ) )( this.transport );
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == "complete") {
this.transport.onreadystatechange = function (){};
}
};
HTTP.Request.VERSION = 0.03;
}
if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
if ( window.XMLHttpRequest ) {
HTTP.Request.Transport = window.XMLHttpRequest;
}
// This tests for ActiveXObject in IE5+
else if ( window.ActiveXObject && window.clipboardData ) {
var msxmls = new Array(
"Msxml2.XMLHTTP.5.0"
,"Msxml2.XMLHTTP.4.0"
,"Msxml2.XMLHTTP.3.0"
,"Msxml2.XMLHTTP"
,"Microsoft.XMLHTTP"
);
for ( var i = 0; i < msxmls.length; i++ ) {
try {
new ActiveXObject(msxmls[i]);
HTTP.Request.Transport = function () {
return new ActiveXObject(msxmls[i]);
};
break;
}
catch(e) {
}
}
}
if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
// This is where we add DIV/IFRAME support masquerading as an XMLHttpRequest object
}
if ( typeof( HTTP.Request.Transport ) == "undefined" ) {
throw new Error("Unable to locate XMLHttpRequest or other HTTP transport mechanism");
}
}
( run in 2.842 seconds using v1.01-cache-2.11-cpan-2398b32b56e )