fetch.html
This file
Path
examples/javascript/js_example/templates/fetch.html
33 lines · 852 bytes · HTML
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than cb4ee20 point at it.
pre-commit updates latest release branchDavid Lordbefore adoptioncb4ee20
lines 1–33why, one step back1{% extends 'base.html' %}23{% block intro %}4 <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch"><code>fetch</code></a>5 is the <em>modern</em> plain JavaScript way to make requests. It's6 supported in all modern browsers.7{% endblock %}89{% block script %}10 <script>11 function addSubmit(ev) {12 ev.preventDefault();13 fetch({{ url_for('add')|tojson }}, {14 method: 'POST',15 body: new FormData(this)16 })17 .then(parseJSON)18 .then(addShow);19 }2021 function parseJSON(response) {22 return response.json();23 }2425 function addShow(data) {26 var span = document.getElementById('result');27 span.innerText = data.result;28 }2930 var form = document.getElementById('calc');31 form.addEventListener('submit', addSubmit);32 </script>33{% endblock %}