/** * class RN_Xml_http * * $Id: xmlHttp.js,v 1.2 2006/01/30 18:24:28 scordeiro Exp $ */ function RN_Xml_Http() { this.request = null; // success/failure callback functions...they are called on completion of request (note behavior diff on async set to false below) this.action_success = null; this.action_faliure = null; // if true, a request in progress is aborted in favor of new request...there is no queue (yet!!!) this.flag_doing_request = false; // if this is true, requests are done in the background // if false, js waits until request is done before continuing code execution // NOTE!!!! on ie, if async is false, callbacks are called as normally // in other browsers, you need call callback explicitly if async is false // (this makes sense as you don't need callback func if you are waiting for the request to finish) this.async = true; } RN_Xml_Http.prototype.setAsync = function(value) { this.async = value; } RN_Xml_Http.prototype.sendRequest = function(fetchtype,url,onSuccess,onFailure,cancelReqInProgress) { // if there is a request in progress and the cacel request flag is true, abort the request in progress if (this.flag_doing_request && cancelReqInProgress==true) { this.request.abort(); this.flag_doing_request = false; } // if there is a request in progress, return if (this.flag_doing_request) { return; } this.action_success = onSuccess; this.action_faliure = onFailure; // Branch for native XMLHttpRequest object if (window.XMLHttpRequest) { this.request = new XMLHttpRequest(); this.request.onreadystatechange = _processReqChange; this.request.open(fetchtype, url, this.async); this.request.send(null); this.flag_doing_request = true; // Branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { this.request = new ActiveXObject("Microsoft.XMLHTTP"); if (this.request) { this.request.onreadystatechange = _processReqChange; this.request.open(fetchtype, url, this.async); this.request.send(); this.flag_doing_request = true; } } return; } RN_Xml_Http.prototype.getResponseText = function() { return this.request.responseText; } RN_Xml_Http.prototype.getResponseXML = function() { return this.request.responseXML; } RN_Xml_Http.prototype.getStatusText = function() { return this.request.statusText; } RN_Xml_Http.prototype.getStatus = function() { return this.request.status; } rnXmlHttp = new RN_Xml_Http(); function _processReqChange() { // State changes // 0 = uninitialized // 1 = loading // 2 = loaded // 3 = interactive // 4 = complete // only if req shows "loaded" if (rnXmlHttp.request.readyState == 4) { rnXmlHttp.flag_doing_request = false; // only if "OK" if (rnXmlHttp.request.status == 200) { rnXmlHttp.action_success(); } else { if (rnXmlHttp.action_faliure==null) { // NEXT LINE MUST BE COMMENTED OUT ON PRODUCTION SYSTEMS //alert("There was a problem retrieving the XML data:\n" + nvXmlHttp.getStatus() + ":\n" + nvXmlHttp.getStatusText()); } else { rnXmlHttp.action_faliure(); } } } return; } function onGenericPageGetFailure() { alert("There was a problem retrieving the XML data:\n" + rnXmlHttp.getStatus() + ":\n" + rnXmlHttp.getStatusText()); }