using vanilla js instead of jquery
This commit is contained in:
parent
9f0398ffae
commit
69c0256439
10881
assets/web/files/jquery.js
vendored
10881
assets/web/files/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,8 @@ if(typeof(EventSource) !== "undefined") {
|
|||||||
var source = new EventSource("/log");
|
var source = new EventSource("/log");
|
||||||
source.onmessage = function(event) {
|
source.onmessage = function(event) {
|
||||||
var j = JSON.parse(event.data);
|
var j = JSON.parse(event.data);
|
||||||
if (j.hasOwnProperty('message')) {
|
/* eslint-disable no-prototype-builtins */
|
||||||
|
if (j.hasOwnProperty("message")) {
|
||||||
document.getElementById("log").innerHTML += j.message + "<br>";
|
document.getElementById("log").innerHTML += j.message + "<br>";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -10,18 +11,20 @@ if(typeof(EventSource) !== "undefined") {
|
|||||||
document.getElementById("log").innerHTML = "Sorry, your browser does not support server-sent events...";
|
document.getElementById("log").innerHTML = "Sorry, your browser does not support server-sent events...";
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#timerForm").submit(function(event){
|
function handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
var $form = $(this),
|
|
||||||
duration = $form.find("input[name='s']").val(),
|
|
||||||
url = $form.attr("action");
|
|
||||||
|
|
||||||
$.ajax({
|
var data = new FormData(event.target)
|
||||||
url: url,
|
var value = Object.fromEntries(data.entries())
|
||||||
type: "POST",
|
var jsonValue = JSON.stringify(value)
|
||||||
data: JSON.stringify({"duration": duration}),
|
|
||||||
contentType: "application/json",
|
|
||||||
dataType: "json"
|
|
||||||
});
|
|
||||||
|
|
||||||
})
|
console.log(jsonValue)
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest()
|
||||||
|
xhr.open("POST", "/api/v1/timer")
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/json")
|
||||||
|
xhr.send(jsonValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
var timerForm = document.querySelector('#timerForm')
|
||||||
|
timerForm.addEventListener('submit', handleSubmit)
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
<h2>Timer</h2>
|
<h2>Timer</h2>
|
||||||
Takes only seconds. Example: 600s
|
Takes only seconds. Example: 600s
|
||||||
<form action="/api/v1/timer" id="timerForm">
|
<form id="timerForm">
|
||||||
<input type="text" name="s" placeholder="600s">
|
<input type="text" name="duration" placeholder="600s">
|
||||||
<input type="submit" value="Set">
|
<input type="submit" value="Set">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@ -25,7 +25,6 @@
|
|||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
<script src=/static/jquery.js></script>
|
|
||||||
<script src=/static/schnutibox.js></script>
|
<script src=/static/schnutibox.js></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user