AjxRpcRequest.js
Summary
No overview generated for 'AjxRpcRequest.js'
Class Summary
|
AjxRpcRequest |
This class represents an XML HTTP request, hiding differences between
browsers. |
function AjxRpcRequest(id, ctxt) {
if (!AjxRpcRequest._inited)
AjxRpcRequest._init();
this.id = id;
this.ctxt = ctxt;
if (AjxEnv.isIE) {
this._httpReq = new ActiveXObject(AjxRpcRequest._msxmlVers);
} else if (AjxEnv.isSafari || AjxEnv.isNav) {
this._httpReq = new XMLHttpRequest();
}
};
AjxRpcRequest._inited = false;
AjxRpcRequest._msxmlVers = null;
AjxRpcRequest.prototype.toString =
function() {
return "AjxRpcRequest";
};
AjxRpcRequest.prototype.invoke =
function(requestStr, serverUrl, requestHeaders, callback, useGet, timeout) {
var asyncMode = (callback != null);
this._httpReq.open((useGet) ? "get" : "post", serverUrl, asyncMode);
if (asyncMode) {
this._callback = callback;
var tempThis = this;
DBG.println(AjxDebug.DBG3, "Async RPC request");
this._httpReq.onreadystatechange = function(ev) {AjxRpcRequest._handleResponse(tempThis, callback);};
} else {
this._httpReq.onreadystatechange = function(ev) {};
}
if (requestHeaders) {
for (var i in requestHeaders) {
this._httpReq.setRequestHeader(i, requestHeaders[i]);
DBG.println(AjxDebug.DBG3, "Async RPC request: Add header " + i + " - " + requestHeaders[i]);
}
}
this._httpReq.send(requestStr);
if (asyncMode) {
return this.id;
} else {
if (this._httpReq.status == 200) {
return {text: this._httpReq.responseText, xml: this._httpReq.responseXML, success: true};
} else {
return {text: this._httpReq.responseText, xml: this._httpReq.responseXML, success: false, status: this._httpReq.status};
}
}
};
AjxRpcRequest._handleResponse =
function(req, callback) {
if (!req) {
DBG.println(AjxDebug.DBG1, "Async RPC request: Lost request object!!!");
callback.run( {text: null, xml: null, success: false, status: 500} );
return;
}
DBG.println(AjxDebug.DBG3, "Async RPC request: ready state = " + req._httpReq.readyState);
if (req._httpReq.readyState == 4) {
if (DBG.getDebugLevel() >= AjxDebug.DBG3)
DBG.println("Async RPC request: HTTP status = " + req._httpReq.status);
if (req._httpReq.status == 200) {
callback.run( {text: req._httpReq.responseText, xml: req._httpReq.responseXML, success: true} );
} else {
callback.run( {text: req._httpReq.responseText, xml: req._httpReq.responseXML, success: false, status: req._httpReq.status} );
}
req.ctxt.busy = false;
}
};
AjxRpcRequest.prototype.cancel =
function() {
DBG.println(AjxDebug.DBG1, "Aborting HTTP request");
this._httpReq.abort();
};
AjxRpcRequest._init =
function() {
if (AjxEnv.isIE) {
var msxmlVers = ["MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i = 0; i < msxmlVers.length; i++) {
try {
var x = new ActiveXObject(msxmlVers[i]);
AjxRpcRequest._msxmlVers = msxmlVers[i];
break;
} catch (ex) {
}
}
if (AjxRpcRequest._msxmlVers == null)
throw new AjxException("MSXML not installed", AjxException.INTERNAL_ERROR, "AjxRpc._init");
}
AjxRpcRequest._inited = true;
};
Documentation generated by
JSDoc on Thu Apr 27 13:58:40 2006