git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
6ae1cb8
Branches
Tags
develop-client_server
master
typescript
fs-words.git
client
source
logic.js
[add] client
Christian Fraß
commited
6ae1cb8
at 2021-03-08 23:52:24
logic.js
Blame
History
Raw
async function api_query ( action_name, input ) { const client = lib_comm.client_http_construct ( { "protocol": "http", "host": "localhost", "port": 7777, "path": "/foo/bar", } ); const message = JSON.stringify ( { "action": action_name, "input": input, } ); const answer = await lib_comm.client_http_send(client, message); if (! (answer.code === 200)) { return Promise.reject("server side error"); } else { const output = JSON.parse(answer.text); return Promise.resolve(output); } } /** */ function main ( ) { document.querySelector("button").addEventListener ( "click", async function () { const language_from = document.querySelector("select[name=language_from]").value; const language_to = document.querySelector("select[name=language_to]").value; const token = document.querySelector("input[name=token]").value; const result = await api_query ( "translate", { "language_from": language_from, "language_to": language_to, "token": token, } ); const dom_ul = document.querySelector("#result"); dom_ul.textContent = ""; for (const entry of result) { let dom_li = document.createElement("li"); dom_li.textContent = (`[${entry.language_from}] ${entry.value_from} ~ [${entry.language_to}] ${entry.value_to}`); dom_ul.appendChild(dom_li); } } ); } document.addEventListener("DOMContentLoaded", function (event) {main();});