-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (26 loc) · 826 Bytes
/
Copy pathindex.ts
File metadata and controls
33 lines (26 loc) · 826 Bytes
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
const input = document.querySelector('input') as HTMLInputElement
const output = document.getElementById('output') as HTMLDivElement
const submitBut = document.getElementById('submit') as HTMLButtonElement
submitBut.addEventListener('click', async (event) => {
output.innerHTML = ''
const query = input.value
if (!query) {
console.log('ERROR: Blank Submission')
output.textContent = 'ERROR: Blank Submission'
return
}
const params = new URLSearchParams({ query })
try {
const resp = await fetch('/endpoint?' + params.toString())
const respJson = await resp.json()
const jsonText = respJson['text']
console.log(jsonText)
for (const ite of jsonText) {
const p = document.createElement('p')
p.textContent = ite
output.appendChild(p)
}
} catch (err) {
console.log(`ERROR: ${err}`)
}
})