1 /* dynamically determine the XMLHTTPRequest server based on
2 where the client is coming from. Good for SSH tunneling, etc. */
4 var _url = "https://" + globalRootURL;
5 if(globalPort != "443")
6 _url = _url + ":" + globalPort;
7 var XML_HTTP_URL = _url + "/gateway";
10 //var XML_HTTP_URL = "https://spacely.georgialibraries.org/gateway";
11 var XML_HTTP_URL = "https://spacely.georgialibraries.org/method/";
15 function RemoteRequest( service, method ) {
17 this.service = service;
22 /* give us the ability to ignore responses from cancelled searches */
23 this.cancelled = false;
25 this.type = "POST"; /* default */
29 while(arguments[i] != null) {
30 var object = js2JSON(arguments[i++]);
31 this.params += "&__param=" + encodeURIComponent(object);
34 if(!this.params) { this.params = ""; }
35 this.param_string = "service=" + service + "&method=" + method + this.params;
36 this.url = XML_HTTP_URL;
38 if( ! this.type || ! this.service || ! this.method ) {
39 alert( "ERROR IN REQUEST PARAMS");
45 this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
48 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
54 if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
55 this.xmlhttp = new XMLHttpRequest();
59 alert("NEEDS NEWER JAVASCRIPT for XMLHTTPRequest()");
65 /* define the callback we use when this request has received
67 RemoteRequest.prototype.setCompleteCallback = function(callback) {
69 var obj = this.xmlhttp;
70 this.callback = callback;
71 this.xmlhttp.onreadystatechange = function() {
72 if( obj.readyState == 4 ) {
80 * By default, all calls are asynchronous. if 'blocking' is
81 * set to true, then the call will block until a response
82 * is received. If blocking, callbacks will not be called.
83 * In other, you can assume the data is avaiable as soon as the
86 RemoteRequest.prototype.send = function(blocking) {
91 if( this.type == 'GET' ) {
92 url += "?" + this.param_string;
96 this.xmlhttp.open(this.type, url, false);
98 this.xmlhttp.open(this.type, url, true);
102 if( this.type == 'POST' ) {
103 data = this.param_string;
104 this.xmlhttp.setRequestHeader('Content-Type',
105 'application/x-www-form-urlencoded');
109 this.xmlhttp.send( data );
112 RemoteRequest.prototype.getText = function() {
113 return this.xmlhttp.responseText;
116 RemoteRequest.prototype.isReady = function() {
117 debug( "Request state is " + this.xmlhttp.readyState );
118 return this.xmlhttp.readyState == 4;
122 RemoteRequest.prototype.getResultObject = function() {
123 var obj = JSON2js( this.xmlhttp.responseText );
125 debug("received null response");
129 if(obj && obj.is_err) {
130 debug("Something's Wrong: " + js2JSON(obj));
131 throw new EXCommunication(obj.err_msg);
134 if( obj[0] != null && obj[1] == null )
140 RemoteRequest.prototype.addParam = function(param) {
141 this.param_string += "&__param=" + escape(js2JSON(param));