1 /* dynamically determine the XMLHTTPRequest server based on
2 where the client is coming from. Good for SSH tunneling, etc. */
3 var _url = "https://" + globalRootURL;
4 if(globalPort != "443")
5 _url = _url + ":" + globalPort;
6 var XML_HTTP_URL = _url + "/gateway";
10 function RemoteRequest( service, method ) {
12 this.service = service;
17 /* give us the ability to ignore responses from cancelled searches */
18 this.cancelled = false;
20 this.type = "POST"; /* default */
24 while(arguments[i] != null) {
25 var object = js2JSON(arguments[i++]);
26 this.params += "&__param=" + encodeURIComponent(object);
29 if(!this.params) { this.params = ""; }
30 this.param_string = "service=" + service + "&method=" + method + this.params;
31 this.url = XML_HTTP_URL;
33 if( ! this.type || ! this.service || ! this.method ) {
34 alert( "ERROR IN REQUEST PARAMS");
40 this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
43 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
49 if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
50 this.xmlhttp = new XMLHttpRequest();
54 alert("NEEDS NEWER JAVASCRIPT for XMLHTTPRequest()");
60 /* define the callback we use when this request has received
62 RemoteRequest.prototype.setCompleteCallback = function(callback) {
64 var obj = this.xmlhttp;
65 this.callback = callback;
66 this.xmlhttp.onreadystatechange = function() {
67 if( obj.readyState == 4 ) {
75 * By default, all calls are asynchronous. if 'blocking' is
76 * set to true, then the call will block until a response
77 * is received. If blocking, callbacks will not be called.
78 * In other, you can assume the data is avaiable as soon as the
81 RemoteRequest.prototype.send = function(blocking) {
86 if( this.type == 'GET' ) {
87 url += "?" + this.param_string;
91 this.xmlhttp.open(this.type, url, false);
93 this.xmlhttp.open(this.type, url, true);
97 if( this.type == 'POST' ) {
98 data = this.param_string;
99 this.xmlhttp.setRequestHeader('Content-Type',
100 'application/x-www-form-urlencoded');
104 this.xmlhttp.send( data );
107 RemoteRequest.prototype.getText = function() {
108 return this.xmlhttp.responseText;
111 RemoteRequest.prototype.getResultObject = function() {
112 var obj = JSON2js( this.xmlhttp.responseText );
115 debug("received null response");
119 if(obj && obj.is_err) {
120 debug("Something's Wrong: " + js2JSON(obj));
121 throw new EXCommunication(obj.err_msg);
124 if( obj[0] != null && obj[1] == null )
130 RemoteRequest.prototype.addParam = function(param) {
131 this.param_string += "&__param=" + escape(js2JSON(param));