home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Joystick Magazine 2003 November
/
CD1_JOY_153.iso
/
demos
/
NHL2004Demo.exe
/
fe
/
COMMON
/
js
/
Remote_Request.js
< prev
next >
Wrap
Text File
|
2003-08-20
|
9KB
|
269 lines
Remote_Request.cacheFileDir = "fe/common/data/"
Remote_Request.cachedRequests = new JAX_Object();
Remote_Request.lkeyTimeouts = 0;
Remote_Request.requestsMade = 0;
Remote_Request.domainId = "&domain=EASO&subdomain=NHL_2003&targetSubdomain=NHL_2003&";
Remote_Request.clearCache = function() {};
function Remote_Request(serverURL, paramStr, isAsync)
{
this.url = (serverURL.match(/[http|https|file]:\/\//gi)) ? serverURL : System.getHostURL() + serverURL;
this.queryString = (paramStr) ? paramStr : "";
this.isPogo = true;
this.isAsyncProp = (isAsync) ? true : false;
this.isPost = true;
this.returnXMLDom = true;
this.error = "";
this.status = "-1";
this.statusText = "-1";
this.badHTTPStatus = false;
this.httpRequest = null;
this.isComplete = false;
this.isSending = false;
this.isAborted = false;
this.value = null;
this.oncomplete = function() {};
this.onstatuschange = function() {};
this.onerror = function() {};
serverURL = paramStr = isAsync = null;
};
Remote_Request.prototype.ID = -100;
Remote_Request.prototype.parseStatus = function()
{
if (this.status != "-1") {
if (!this.status.match(/200/gi)) { this.badHTTPStatus = true; };
};
return ("::" + this.status + "::" + this.statusText);
};
Remote_Request.prototype.isResponseValid = function()
{
var bIsValid = false;
if (this.isComplete) {
if (this.value) {
if (this.value.match(/(?:\:\:\d+\:\:|\:\:\-\d+\:\:)/g)) {
this.error = this.value.replace(/<SERVER_ERROR>/gi, "");
this.error = this.error.replace(/<\/SERVER_ERROR>/gi, "");
this.error = this.error.replace(/(^\s*)|(\s*$)/g, "");
} else if (this.value.match(/not found.*404/gi)) {
this.error = "::99::" + scMsg("SC_REGERROR_99");
} else {
bIsValid = true;
};
} else {
this.error ="::501::Server not responding";
};
};
return bIsValid;
};
Remote_Request.prototype.cacheRequest = function() {};
Remote_Request.prototype.setIsPogoRequest = function(bool) { this.isPogo = (bool) ? true : false; bool=null;};
Remote_Request.prototype.setIsPostRequest = function(bool) { this.isPost = (bool) ? true : false; bool=null; };
Remote_Request.prototype.setReturnXML_DOM = function(bool) { this.returnXMLDom = (bool) ? true : false; bool=null; };
Remote_Request.prototype.setOnStatusChange = function(fHandler) { this.onstatuschange = fHandler;fHandler=null; };
Remote_Request.prototype.setOnComplete = function(fHandler) { this.oncomplete = fHandler; fHandler=null; };
Remote_Request.prototype.setID = function(id) { this.ID = id; id=null };
Remote_Request.prototype.getURL = function() { return this.url; };
Remote_Request.prototype.isAsync = function() { return this.isAsyncProp; };
Remote_Request.prototype.isError = function() { return this.error; };
Remote_Request.prototype.getValue = function() { return this.value; };
Remote_Request.prototype.getID = function() { return this.ID; };
Remote_Request.prototype.parseErrorCode = function()
{
var returnValue = this.error.match(/\:\:\d+\:\:/g);
if (returnValue) {
returnValue = returnValue.toString();
returnValue = returnValue.replace(/\:\:/g, "");
returnValue = parseInt(returnValue);
};
return returnValue;
};
Remote_Request.prototype.send = function()
{
if (gblRRManager.isAborting || this.isAborted) {
gblRRManager.unregister(this);
CollectGarbage();
return;
};
this.httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
if (this.isAsyncProp) {
var ti = this;
var nRequestID = gblRRManager.register(ti);
if (nRequestID == -500) { return; };
this.httpRequest.onreadystatechange = function()
{
if (gblRRManager.isAborting || ti.isAborted) {
gblRRManager.unregister(ti);
ti = ti.httpRequest = ti.oncomplete = ti.onerror = ti.onstatuschange = null;
CollectGarbage();
return;
};
if (ti.httpRequest.readyState != 4) {
if (ti.onstatuschange) {
ti.onstatuschange();
};
try {
ti.status = ti.httpRequest.status;
ti.statusText = ti.httpRequest.statusCode;
} catch (e) {}
} else {
ti.isSending = false;
ti.isComplete = true;
try {
ti.status = ti.httpRequest.status;
ti.statusText = ti.httpRequest.statusCode;
} catch (e) {}
if (!ti.isImage) {
ti.value = ti.httpRequest.responseText;
ti.isvalid = ti.isResponseValid();
} else {
ti.value = ti.httpRequest.responseStream;
try {
if (ti.oncomplete && !gblRRManager.isAborting) {
ti.oncomplete();
};
} catch (e) {
if (e.name == "Error" && e.number == -2147467259) {
//freed script error;
} else {
throw e;
};
} finally {
gblRRManager.unregister(ti);
ti = ti.httpRequest = ti.oncomplete = ti.onerror = ti.onstatuschange = null;
CollectGarbage();
return;
};
};
if (ti.isvalid) {
if (ti.returnXMLDom) {
if (ti.httpRequest.responseXML.xml) {
ti.value = ti.httpRequest.responseXML;
} else {
ti.value = new ActiveXObject("MSXML2.DOMDocument");
ti.value.async = false;
ti.loaded = ti.value.loadXML(ti.httpRequest.responseText);
if (!ti.loaded) {
ti.value = ti.httpRequest.responseText;
ti.error = "::99::XML DOM NOT RETURNED";
} else {
};
delete ti.loaded;
};
};
} else {
if (ti.onerror) {
ti.onerror();
};
};
delete ti.isvalid;
if (ti.error.match(/\:\:-1\:\:/g)) {
gblRRManager.doCancel();
ti = ti.httpRequest = ti.oncomplete = ti.onerror = ti.onstatuschange = null;
CollectGarbage();
return;
};
try {
if (ti.oncomplete && !gblRRManager.isAborting) {
ti.oncomplete();
};
} catch (e) {
if (e.name == "Error" && e.number == -2147467259) {
//freed script error;
} else {
throw e;
};
} finally {
gblRRManager.unregister(ti);
ti = ti.httpRequest = ti.oncomplete = ti.onerror = ti.onstatuschange = null;
CollectGarbage();
};
};
};
};
if (this.isPogo) {
this.url = this.url.replace(/\/sc\//i, "/easo/nhl03/");
this.url += "?site=pogo&lkey=" + System.Session.getUserLKey() + Remote_Request.domainId;
if (!this.isPost) { this.url += this.queryString; };
} else {
this.url += "?" + this.queryString;
};
if (!this.isAborted && !gblRRManager.isAborting) {
this.isSending = true;
if (this.isPost) {
this.httpRequest.Open("POST", this.url, this.isAsyncProp);
this.httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
this.httpRequest.send(this.queryString);
} else {
if (!this.isImage) {
this.httpRequest.Open("GET", this.url + "&easo_date=" + escape(new Date()) + "&", this.isAsyncProp);
this.httpRequest.send();
} else {
this.httpRequest.Open("GET", this.url + "&easo_date=" + escape(new Date()) , this.isAsyncProp);
this.httpRequest.setRequestHeader("Content-Type", "image/gif");
//this.httpRequest.setRequestHeader("Cache-Control", "no-cache");
this.httpRequest.send();
};
};
};
if (!this.isAsyncProp) {
try {
ti.status = ti.httpRequest.status;
ti.statusText = ti.httpRequest.statusCode;
} catch (e) {}
this.isSending = false;
this.value = this.httpRequest.responseText;
this.isComplete = true;
this.isvalid = this.isResponseValid();
if (this.isvalid) {
if (this.returnXMLDom) {
if (this.httpRequest.responseXML.xml) {
this.value = this.httpRequest.responseXML;
} else {
this.value = new ActiveXObject("MSXML2.DOMDocument");
this.value.async = false;
this.loaded = this.value.loadXML(this.httpRequest.responseText);
if (!this.loaded) {
this.value = this.httpRequest.repsonseText;
ti.error = "::99::XML DOM NOT RETURNED";
};
delete this.loaded;
};
};
} else {
this.onerror();
};
this.oncomplete();
this.isvalid = this.httpRequest = this.oncomplete = this.onerror = this.onstatuschange = null;
delete this.isvalid; delete this.httpRequest; delete this.oncomplete; delete this.onerror; delete this.onstatuschange;
CollectGarbage();
};
};
Remote_Request.prototype.isValueDOM = function()
{
if (this.value.xml) {
return true;
};
return false;
};
Remote_Request.prototype.abort = function()
{
this._killFunctions();
this.isSending = false;
this.isAborted = true;
this.httpRequest.onreadystatechange = function() { return false; };
this.httpRequest.abort();
this.httpRequest =null;
gblRRManager.unregister(this);
};
Remote_Request.prototype._killFunctions = function()
{
this.isReponseValid = Remote_Request.temp_function;
this.isError = Remote_Request.temp_function;
this.parseErrorCode = Remote_Request.temp_function;
this.send = Remote_Request.temp_function;
this.oncomplete = Remote_Request.temp_function;
this.getValue = Remote_Request.temp_function;
};
Remote_Request.temp_function = function() {};