fetch.html
This file
Path
examples/javascript/js_example/templates/fetch.html
33 lines · 852 bytes · HTML
Last changed by
Merge pull request #4636 from pallets/docs-javascriptDavid Lordbefore adoption9398630
History of this fileTake it
The walk stopped after 200 commits: lines older than de0af03 point at it.
Merge remote-tracking branch 'origin/1.1.x'Grey Libefore adoptionde0af03
lines 1–4why, 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>Merge pull request #4636 from pallets/docs-javascriptDavid Lordbefore adoption9398630
lines 5–6why, one step back5 is the <em>modern</em> plain JavaScript way to make requests. It's6 supported in all modern browsers.Merge remote-tracking branch 'origin/1.1.x'Grey Libefore adoptionde0af03
lines 7–33why, one step back7{% 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 %}