show errors in demo

Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
hrj 2021-04-19 18:05:59 +05:30
parent 8595b2cc79
commit 9b978212dc
1 changed files with 26 additions and 13 deletions

View File

@ -8,15 +8,24 @@
</style>
<script>
function showError(errMessage) {
const resultDiv = document.getElementById("result")
const result = `
<p>Error: ${errMessage}</p>
`
resultDiv.innerHTML = result;
}
async function loadCaptcha() {
const levelInput = document.getElementById("levelInput").value
const mediaInput = document.getElementById("mediaInput").value
const typeInput = document.getElementById("typeInput").value
const resp = await fetch("/v1/captcha", {
fetch("/v1/captcha", {
method: 'POST',
body: JSON.stringify({level: levelInput, media: mediaInput, "input_type" : typeInput})
})
}).then(async function(resp) {
const respJson = await resp.json()
if (resp.ok) {
const id = respJson.id
const resultDiv = document.getElementById("result")
const result = `
@ -27,6 +36,10 @@
<div id="answerResult" />
`
resultDiv.innerHTML = result;
} else {
showError("Failed with response code: " + resp.status + " response: " + JSON.stringify(respJson))
}
}).catch(showError)
}
async function submitAnswer(id) {
const ans = document.getElementById("answerInput").value;