1 karl 1.2.2.2 /*!LICENSE
2 *
3 * Licensed to The Open Group (TOG) under one or more contributor license
4 * agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 * this work for additional information regarding copyright ownership.
6 * Each contributor licenses this file to you under the OpenPegasus Open
7 * Source License; you may not use this file except in compliance with the
8 * License.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 karl 1.2.2.2 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 */
29
30 //check if it is http or https
31 httpTag =document.location.protocol;
32 //base url which is identical for all requests
33 baseURL = httpTag+"//"+window.location.hostname+":"+window.location.port+"/cimrs/";
34 host = httpTag+"//"+window.location.hostname+":"+window.location.port+"/";
35
36 function genericRequestGet(urlAdd, funcToCall, synchronous){
37 /*
38 * based on api example from:
39 * https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Example.3a_Asynchronous_request
40 */
41
42
43 karl 1.2.2.2 if (funcToCall == "writeContent")
44 funcToCall = writeContent;
45
46 try {
47 var req = new XMLHttpRequest();
48 } catch(e) {
49 alert('No support for XMLHTTPRequests');
50 return;
51 }
52 var url = baseURL + urlAdd;
53
54 var async = synchronous;
55 req.open('GET', url, async);
56
57 // add progress listener (differs from version to version...)
58 req.onreadystatechange = function () {
59 // state complete is of interest, only
60 if (req.readyState == 4) {
61 if (req.status == 200) {
62 //call of the passed function (as parameter)
63 funcToCall(req.responseText);
64 karl 1.2.2.2 //dump(req.responseText);
65 } else {
66 //if return code is another than 200 process error
67 processRequestError(req.responseText);
68
69 }
70 }
71 };
72
73 // send request
74 req.send();
75
76 }
77
78
79 function genericRequestPost(requestURL, requestContent,funcToCall, synchronous){
80 /*
81 * based on api example from:
82 * https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Example.3a_Asynchronous_request
83 */
84
85 karl 1.2.2.2 try {
86 var req = new XMLHttpRequest();
87 } catch(e) {
88 alert('No support for XMLHTTPRequests');
89 return;
90 }
91 var url = baseURL + requestURL;
92
93 var async = synchronous;
94 req.open('POST', url, async);
95 req.setRequestHeader('Content-Type', 'application/json');
96
97 // add progress listener (differs from version to version...)
98 req.onreadystatechange = function () {
99 // state complete is of interest, only
100 if (req.readyState == 4) {
101 if (req.status == 200) {
102 //call of the passed function (as parameter)
103 funcToCall(req.responseText);
104 //dump(req.responseText);
105 } else {
106 karl 1.2.2.2 //if return code is another than 200 process error
107 processRequestError(req.responseText);
108
109 }
110 }
111 };
112
113 // send request
114 req.send(JSON.stringify(requestContent));
115
116 }
117
118
|