add button!

This commit is contained in:
ducoterra
2020-04-24 20:30:27 -04:00
parent 02d2f9d7e6
commit 150f48f17c
13 changed files with 135 additions and 0 deletions

35
ui/static/ui/button.js Normal file
View File

@@ -0,0 +1,35 @@
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
var button = document.getElementById("BUTTON");
var count = document.getElementById("COUNT");
button.addEventListener("click", event => {
fetch('/button', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrftoken
}
})
.then((response) => {
return response.json();
})
.then((data) => {
count.innerText = data.pressed;
});
})