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