Added better error messages, and tested json API
This commit is contained in:
@@ -6,8 +6,50 @@
|
||||
|
||||
<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}"/>
|
||||
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>
|
||||
Reference in New Issue
Block a user