55 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<div th:replace="~{html-head}"/>
</head>
<body>
<div th:replace="~{header}"/>
<script th:src="@{/webjars/jquery/1.9.1/jquery.min.js}"></script>
<main>
Youhou ! (Y devrait y avoir le form ici ^^) <span th:text="${formid}"/> <br/>
<button id="question-button">Poser la question</button>
<button id="answer1-button">Première réponse</button>
<script>
e = new RegExp("/([0-9]+)$")
e.test(window.location.href)
qid = Number(RegExp.lastMatch.substring(1))
qindex = 0
qstep = 0
function next() {
$.ajax({
url: "/questions/question/"+qid,
type: "GET",
dataType: "json",
success: function(res) {
console.log(res)
qindex=res["index"]
qstep=res["step"]
}
})
}
function answer() {
asw={
index: qindex,
step: qstep,
data: Math.floor(Math.random() * 3)*2
}
$.ajax({
contentType: 'application/json',
type: "POST",
url: "/questions/answer/"+qid,
data: JSON.stringify(asw),
dataType: "json",
success: function(res) {
console.log(res)
}
})
}
$("#question-button").on('click',next)
$("#answer1-button").on('click',answer)
</script>
</main>
</body>
</html>