Skip to content
Myr

xhr.html

This file

Path

examples/javascript/js_example/templates/xhr.html

29 lines · 933 bytes · HTML

Last changed by

Merge pull request #4636 from pallets/docs-javascriptDavid Lordbefore adoption9398630

History of this file

Take it

Merge pull request #4636 from pallets/docs-javascriptDavid Lordbefore adoption9398630

lines 1–29why, one step back
1{% extends 'base.html' %}
23{% block intro %}4 <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"><code>XMLHttpRequest</code></a>5 is the original JavaScript way to make requests. It's natively supported6 by all browsers, but has been superseded by7 <a href="{{ url_for("index", js="fetch") }}"><code>fetch</code></a>.8{% endblock %}910{% block script %}11 <script>12 function addSubmit(ev) {13 ev.preventDefault();14 var request = new XMLHttpRequest();15 request.addEventListener('load', addShow);16 request.open('POST', {{ url_for('add')|tojson }});17 request.send(new FormData(this));18 }1920 function addShow() {21 var data = JSON.parse(this.responseText);22 var span = document.getElementById('result');23 span.innerText = data.result;24 }2526 var form = document.getElementById('calc');27 form.addEventListener('submit', addSubmit);28 </script>29{% endblock %}