XML DOM, XPath and XMLHttpRequest support for O::U::SpiderMonkey
[Evergreen.git] / Open-ILS / src / javascript / backend / libs / xmlhttprequest.js
1 load_lib('jsOO.js');
2 load_lib('jsDOM.js');
3
4 var __xmlhttpreqid = 1;
5 var __xmlhttpreq_hash = {};
6
7 function XMLHttpRequest () {
8         // Cache this for later ...
9         this._hash_id = __xmlhttpreqid;
10         __xmlhttpreqid++;
11 }
12
13 XMLHttpRequest.method('open',function (method, url, async) {
14         this._method = method;
15         this._url = url;
16         this._async = (async ? 1 : 0);
17 });
18
19 XMLHttpRequest.method('setRequestHeader', function (header, header_value) {
20         if (!this._headers) this._headers = {}
21         this._headers[header] = header_value;
22 });
23
24 XMLHttpRequest.method('send', function (data) {
25
26         var headerlist = '';
27         for (var i in this._headers) {
28                 headerlist = headerlist + '\n' + i + '|' + this._headers[i];
29         }
30
31         __xmlhttpreq_hash['id' + this._hash_id] = {};
32
33         _OILS_FUNC_xmlhttprequest_send(this._hash_id,this._method,this._url,this._async,headerlist,data);
34
35         this.responseText = __xmlhttpreq_hash['id' + this._hash_id].responseText;
36         this.readyState = __xmlhttpreq_hash['id' + this._hash_id].readyState;
37         this.status = __xmlhttpreq_hash['id' + this._hash_id].status;
38         this.statusText = __xmlhttpreq_hash['id' + this._hash_id].statusText;
39         this.responseXML = DOMImplementation.parseString(this.responseText);
40
41         if (this._async)
42                 this.onreadystatechange();
43 });
44
45