Skip to content
Myr

plain.html

This file

Path

examples/javascript/js_example/templates/plain.html

27 lines · 792 bytes · HTML

Last changed by

Merge pull request #2699 from pallets/javascriptDavid Lordbefore adoption746b91d

History of this file

Take it

Merge pull request #2699 from pallets/javascriptDavid Lordbefore adoption746b91d

lines 1–27why, 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 plain JavaScript way to make requests. It's natively supported6 by all browsers.7{% endblock %}89{% block script %}10 <script>11 function addSubmit(ev) {12 ev.preventDefault();13 var request = new XMLHttpRequest();14 request.addEventListener('load', addShow);15 request.open('POST', '{{ url_for('add') }}');16 request.send(new FormData(this));17 }1819 function addShow() {20 var data = JSON.parse(this.responseText);21 var span = document.getElementById('result');22 span.innerText = data.result;23 }2425 document.forms[0].addEventListener('submit', addSubmit);26 </script>27{% endblock %}