forked from OSBI/saiku-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajaxtest.html
174 lines (141 loc) · 6.43 KB
/
ajaxtest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Saiku - Next Generation Open Source Analytics</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/smoothness/jquery-ui.css" type="text/css" media="all" />
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
;(function (window) {
var
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
fromCharCode = String.fromCharCode,
INVALID_CHARACTER_ERR = (function () {
// fabricate a suitable error object
try { document.createElement('$'); }
catch (error) { return error; }}());
// encoder
window.Base64 || (
window.Base64 = { encode: function (string) {
var
a, b, b1, b2, b3, b4, c, i = 0,
len = string.length, max = Math.max, result = '';
while (i < len) {
a = string.charCodeAt(i++) || 0;
b = string.charCodeAt(i++) || 0;
c = string.charCodeAt(i++) || 0;
if (max(a, b, c) > 0xFF) {
throw INVALID_CHARACTER_ERR;
}
b1 = (a >> 2) & 0x3F;
b2 = ((a & 0x3) << 4) | ((b >> 4) & 0xF);
b3 = ((b & 0xF) << 2) | ((c >> 6) & 0x3);
b4 = c & 0x3F;
if (!b) {
b3 = b4 = 64;
} else if (!c) {
b4 = 64;
}
result += characters.charAt(b1) + characters.charAt(b2) + characters.charAt(b3) + characters.charAt(b4);
}
return result;
}});
}(this));
</script>
Cookie:<div id="cookie" />
<div>
Login<br>
<input type="text" id="username"/></br>
Password<br>
<input type="text" id="password"/></br>
User:<div id="user" ></div>
Pass:<div id="pass" ></div>
</br>
</div>
<input id="call" type="submit" value="login"/><br/>
<input id="session" type="submit" value="session"/><br/>
<input id="test" type="submit" value="test"/><br/>
<input id="logout" type="submit" value="logout"/><br/>
Request:<div id="result"></div>
Logout:<div id="logoutresult"></div>
<script type="text/javascript">
var username='';
var password='';
success = function(data, textStatus, jqXHR) {
$("<span style='color:green;'>" + username + ":" + password + " = " + jqXHR.status + " … " +jqXHR.statusText + " </span><br/>").appendTo("#result");
};
failure = function(jqXHR, textStatus, errorThrown) {
$("<span style='color:red;'>" + username + ":" + password + " = " + jqXHR.status + " … " +jqXHR.statusText + " </span><br/>").appendTo("#result");
};
$('#call').click(function() {
username= $('#username').val();
password= $('#password').val();
this.success = function(data, textStatus, jqXHR) {
$("<span style='color:green;'>" + username + ":" + password + " = " + jqXHR.status + " … " +jqXHR.statusText + "..." + JSON.stringify(data) + " </span><br/>").appendTo("#result");
};
this.failure = function(jqXHR, textStatus, errorThrown) {
$("<span style='color:red;'>" + username + ":" + password + " = " + jqXHR.status + " … " +jqXHR.statusText + " </span><br/>").appendTo("#result");
};
params = {
url: "/saiku/rest/session",
type: "POST",
cache: false,
contentType: 'application/x-www-form-urlencoded',
success: success,
error: failure,
data: {username:username, password:password},
beforeSend: function(request) {
// alert('xhr:' + username + ":" + password);
// var auth = "Basic " + Base64.encode(username + ":" + password);
// request.setRequestHeader('Authorization', auth);
}
};
$.ajax(params);
return false;
});
$('#test').click(function() {
username= $('#username').val();
password= $('#password').val();
params = {
url: "/saiku/rest/saiku/{username}/discover",
type: "GET",
cache: false,
contentType: 'application/x-www-form-urlencoded',
success: success,
error: failure,
beforeSend: function(request) {
// alert('xhr:' + username + ":" + password);
// var auth = "Basic " + Base64.encode(username + ":" + password);
// request.setRequestHeader('Authorization', auth);
}
};
$.ajax(params);
return false;
});
$('#session').click(function() {
username= $('#username').val();
password= $('#password').val();
params = {
url: "/saiku/rest/session",
type: "GET",
cache: false,
contentType: 'application/x-www-form-urlencoded',
success: success,
error: failure,
};
$.ajax(params);
return false;
});
$('#logout').click(function() {
$.ajax({
url: "/saiku/rest/session",
type: "DELETE",
});
return false;
});
</script>
</body>
</html>