1 XObject = imports.XObject.XObject;
3 Soup = imports.gi.Soup;
5 var XMLHttpRequest = function (cfg) {
6 if (typeof(cfg) == 'object') {
14 XMLHttpRequest.prototype = {
26 withCredentials : false,
45 open : function ( method, url, async, user, password)
47 async = async || false;
49 password = password || false;
51 this._session = async ? new Soup.SessionAsync() : new Soup.SessionSync();
53 var uri = new Soup.URI.c_new(url);
54 this._message = new Soup.Message({method: method, uri:uri});
57 if (user || password) {
59 password = password || '';
60 var auth = new Soup.Auth.c_new(
63 "Basic realm=\"Test\"");
67 auth.authenticate(user,password);
68 var authmsg = auth.get_authorization(this._message);
70 this._message.request_headers.append(
71 'Authorization', authmsg);
78 setRequestHeader : function ( header, value)
80 _this.message.request_headers.append(headers, value)
83 overrideMimeType : function ( mime)
91 if (typeof(data) == 'object') {
93 data = this.urlEncode(data);
97 this._message.set_request('application/x-www-form-urlencoded', Soup.MemoryUse.COPY, data, data.length)
101 this._session.queue_message(this._message, function(ses, msg) {
102 // doc's say we get here after we have sent the data..
104 //print("got queue callback");
105 //_t._session.unpause_message(this._message);
106 //print("queue message");
107 //print(_t._message.response_body.data)
108 _t.responseText = _t._message.response_body.data;
111 if (_t.onreadystatechange) {
112 _t.onreadystatechange();
120 var status = this._session.send_message(this._message);
121 this.responseText = this._message.response_body.data;
123 if (_t.onreadystatechange) {
124 _t.onreadystatechange();
134 // response (all readonly...)
137 //readonly attribute any response
138 responseText : false,
140 responseType : false,
143 getResponseHeader : function( header)
147 getAllResponseHeaders : function ()
151 urlEncode : function(o){
157 var ov = o[key], k = encodeURIComponent(key);
158 var type = typeof ov;
159 if(type == 'undefined'){
161 }else if(type != "function" && type != "object"){
162 buf.push(k, "=", encodeURIComponent(ov), "&");
163 }else if(ov instanceof Array){
165 for(var i = 0, len = ov.length; i < len; i++) {
166 buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");