-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (33 loc) · 926 Bytes
/
main.js
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
access_token = "SERVER_ACCESS_TOKEN";
function today() {
return new Date().toISOString().slice(0, 10).replace("-", "");
}
function getQuery() {
return document.getElementById("request").value;
}
function get() {
setLoading();
fetch("https://api.wit.ai/message?v=" + today() + "&q=" + getQuery(),
{
headers: {
Authorization: "Bearer " + access_token
}
}).then(response => response.json())
.then(data => {
setResponse(stringify(data));
console.log(data);
})
.catch(error => {
setResponse(stringify(error));
return console.error(error);
})
}
function stringify(data) {
return JSON.stringify(data, undefined, 2)
}
function setLoading() {
setResponse("Loading ...");
}
function setResponse(response) {
document.getElementById("response").innerText = response;
}