Spaces:
Running
Running
Create common.js
Browse files- static/common.js +18 -0
static/common.js
ADDED
@@ -0,0 +1,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 |
+
document.getElementById(id).innerText = data.message || JSON.stringify(data, null, 2);
|
18 |
+
}
|