Update readBadge JS script

This commit is contained in:
jarjar 2023-05-31 09:07:28 +00:00
parent 8534574862
commit e2c3392ff9

View File

@ -21,28 +21,25 @@
</body> </body>
</html> </html>
<script> <script>
var xhr = new XMLHttpRequest(); fetch('/detectBadge')
xhr.open('GET', '/detectBadge', true); .then(response => response.json())
xhr.onload = function() { .then(jsonresponse => {
var jsonreponse = JSON.parse(xhr.response); if (jsonresponse.status == "OK") {
if (jsonreponse.status == "OK") {
document.getElementById("info").textContent = "Tentative de copie du badge ..."; document.getElementById("info").textContent = "Tentative de copie du badge ...";
return fetch('/readBadge');
var xhr2 = new XMLHttpRequest();
xhr2.open('GET', '/readBadge', true);
xhr2.onload = function() {
var jsonreponse = JSON.parse(xhr2.response);
if (jsonreponse.status == "OK") {
window.location.href = "/wait?raison=Appuyer%20sur%20le%20bouton%20pour%20commencer%20la%20copie%20des%20badges.&redirect=/writeBadge/{{nbBadge}}/" + jsonreponse.UID;
} else {
window.location.href = "/?error=" + jsonreponse.message;
}
};
xhr2.send(null);
} else { } else {
window.location.href = "/?error=" + jsonreponse.message; throw new Error(jsonresponse.message);
} }
}; })
.then(response => response.json())
xhr.send(null); .then(jsonresponse => {
if (jsonresponse.status == "OK") {
window.location.href = `/wait?raison=Appuyer%20sur%20le%20bouton%20pour%20commencer%20la%20copie%20des%20badges.&redirect=/writeBadge/{{nbBadge}}/${jsonresponse.UID}`;
} else {
throw new Error(jsonresponse.message);
}
})
.catch(error => {
window.location.href = `/?error=${error.message}`;
});
</script> </script>