mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
show errors in demo
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
8595b2cc79
commit
9b978212dc
@ -8,25 +8,38 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
function showError(errMessage) {
|
||||||
|
const resultDiv = document.getElementById("result")
|
||||||
|
const result = `
|
||||||
|
<p>Error: ${errMessage}</p>
|
||||||
|
`
|
||||||
|
resultDiv.innerHTML = result;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadCaptcha() {
|
async function loadCaptcha() {
|
||||||
const levelInput = document.getElementById("levelInput").value
|
const levelInput = document.getElementById("levelInput").value
|
||||||
const mediaInput = document.getElementById("mediaInput").value
|
const mediaInput = document.getElementById("mediaInput").value
|
||||||
const typeInput = document.getElementById("typeInput").value
|
const typeInput = document.getElementById("typeInput").value
|
||||||
const resp = await fetch("/v1/captcha", {
|
fetch("/v1/captcha", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({level: levelInput, media: mediaInput, "input_type" : typeInput})
|
body: JSON.stringify({level: levelInput, media: mediaInput, "input_type" : typeInput})
|
||||||
})
|
}).then(async function(resp) {
|
||||||
const respJson = await resp.json()
|
const respJson = await resp.json()
|
||||||
const id = respJson.id
|
if (resp.ok) {
|
||||||
const resultDiv = document.getElementById("result")
|
const id = respJson.id
|
||||||
const result = `
|
const resultDiv = document.getElementById("result")
|
||||||
<p>Id: ${id}</p>
|
const result = `
|
||||||
<p><img src="/v1/media?id=${id}" /> </p>
|
<p>Id: ${id}</p>
|
||||||
<input type="text" id="answerInput" />
|
<p><img src="/v1/media?id=${id}" /> </p>
|
||||||
<button onClick="submitAnswer('${id}')">Submit</button>
|
<input type="text" id="answerInput" />
|
||||||
<div id="answerResult" />
|
<button onClick="submitAnswer('${id}')">Submit</button>
|
||||||
`
|
<div id="answerResult" />
|
||||||
resultDiv.innerHTML = result;
|
`
|
||||||
|
resultDiv.innerHTML = result;
|
||||||
|
} else {
|
||||||
|
showError("Failed with response code: " + resp.status + " response: " + JSON.stringify(respJson))
|
||||||
|
}
|
||||||
|
}).catch(showError)
|
||||||
}
|
}
|
||||||
async function submitAnswer(id) {
|
async function submitAnswer(id) {
|
||||||
const ans = document.getElementById("answerInput").value;
|
const ans = document.getElementById("answerInput").value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user