fetch.html
This file
Path
examples/javascript/js_example/templates/fetch.html
36 lines · 1.1 KiB · HTML
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f325b8b point at it.
add lock threads workflowDavid Lordbefore adoptionf325b8b
lines 1–36why, 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>new</em> plain JavaScript way to make requests. It's6 supported in all modern browsers except IE, which requires a7 <a href="https://github.com/github/fetch">polyfill</a>.8{% endblock %}910{% block script %}11 <script src="https://unpkg.com/promise-polyfill@7.1.2/dist/polyfill.min.js"></script>12 <script src="https://unpkg.com/whatwg-fetch@2.0.4/fetch.js"></script>13 <script>14 function addSubmit(ev) {15 ev.preventDefault();16 fetch({{ url_for('add')|tojson }}, {17 method: 'POST',18 body: new FormData(this)19 })20 .then(parseJSON)21 .then(addShow);22 }2324 function parseJSON(response) {25 return response.json();26 }2728 function addShow(data) {29 var span = document.getElementById('result');30 span.innerText = data.result;31 }3233 var form = document.getElementById('calc');34 form.addEventListener('submit', addSubmit);35 </script>36{% endblock %}