Spaces:
Running
Running
Update static/js/common.js
Browse files- static/js/common.js +25 -18
static/js/common.js
CHANGED
@@ -1,18 +1,25 @@
|
|
1 |
-
const apiBase = '';
|
2 |
-
|
3 |
-
function apiPost(path, body) {
|
4 |
-
return fetch(`${apiBase}${path}`, {
|
5 |
-
method: 'POST',
|
6 |
-
headers: { 'Content-Type': 'application/json' },
|
7 |
-
body: JSON.stringify(body)
|
8 |
-
}).then(res => res.json());
|
9 |
-
}
|
10 |
-
|
11 |
-
function apiGet(path) {
|
12 |
-
return fetch(`${apiBase}${path}`)
|
13 |
-
.then(res => res.json());
|
14 |
-
}
|
15 |
-
|
16 |
-
function showResult(id, data) {
|
17 |
-
document.getElementById(id)
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const apiBase = '';
|
2 |
+
|
3 |
+
function apiPost(path, body) {
|
4 |
+
return fetch(`${apiBase}${path}`, {
|
5 |
+
method: 'POST',
|
6 |
+
headers: { 'Content-Type': 'application/json' },
|
7 |
+
body: JSON.stringify(body)
|
8 |
+
}).then(res => res.json());
|
9 |
+
}
|
10 |
+
|
11 |
+
function apiGet(path) {
|
12 |
+
return fetch(`${apiBase}${path}`)
|
13 |
+
.then(res => res.json());
|
14 |
+
}
|
15 |
+
|
16 |
+
function showResult(id, data) {
|
17 |
+
const el = document.getElementById(id);
|
18 |
+
if (data.detail) {
|
19 |
+
el.innerText = data.detail;
|
20 |
+
el.classList.add('text-danger');
|
21 |
+
} else {
|
22 |
+
el.innerText = data.message || JSON.stringify(data, null, 2);
|
23 |
+
el.classList.remove('text-danger');
|
24 |
+
}
|
25 |
+
}
|