1 //var XML_HTTP_URL = "https://spacely.georgialibraries.org/method/";
2 //var XML_HTTP_URL = "https://localhost:10444/method/";
3 var XML_HTTP_URL = "https://spacely.georgialibraries.org/gateway";
6 function RemoteRequest( service, method ) {
8 this.service = service;
13 /* give us the ability to ignore responses from cancelled searches */
14 this.cancelled = false;
16 //this.type = "POST"; /* default */
17 this.type = "GET"; /* default */
21 while(arguments[i] != null) {
22 var object = js2JSON(arguments[i++]);
23 this.params += "&__param=" + encodeURIComponent(object);
26 if(!this.params) { this.params = ""; }
27 this.param_string = "service=" + service + "&method=" + method + this.params;
28 this.url = XML_HTTP_URL;
30 if( ! this.type || ! this.service || ! this.method ) {
31 alert( "ERROR IN REQUEST PARAMS");
37 this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
40 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
46 if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
47 this.xmlhttp = new XMLHttpRequest();
51 alert("NEEDS NEWER JAVASCRIPT for XMLHTTPRequest()");
59 /* define the callback we use when this request has received
61 RemoteRequest.prototype.setCompleteCallback = function(callback) {
63 var obj = this.xmlhttp;
64 this.callback = callback;
65 this.xmlhttp.onreadystatechange = function() {
66 if( obj.readyState == 4 ) {
74 * By default, all calls are asynchronous. if 'blocking' is
75 * set to true, then the call will block until a response
76 * is received. If blocking, callbacks will not be called.
77 * In other, you can assume the data is avaiable as soon as the
80 RemoteRequest.prototype.send = function(blocking) {
85 if( this.type == 'GET' ) {
86 url += "?" + this.param_string;
90 this.xmlhttp.open(this.type, url, false);
92 this.xmlhttp.open(this.type, url, true);
96 if( this.type == 'POST' ) {
97 data = this.param_string;
98 this.xmlhttp.setRequestHeader('Content-Type',
99 'application/x-www-form-urlencoded');
103 this.xmlhttp.send( data );
106 RemoteRequest.prototype.getText = function() {
107 return this.xmlhttp.responseText;
110 RemoteRequest.prototype.getResultObject = function() {
111 var obj = JSON2js( this.xmlhttp.responseText );
113 debug("Request " + this.param_string +
114 "\nReceived\n" + this.xmlhttp.responseText);
117 alert("received null response");
121 if(obj && obj.is_err) {
122 alert("Something's Wrong: " + js2JSON(obj));
123 throw new EXCommunication(obj.err_msg);
129 RemoteRequest.prototype.addParam = function(param) {
130 this.param_string += "&__param=" + escape(js2JSON(param));