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 fileTake it
12345678910111213141516171819202122232425262728{% extends 'base.html' %}
{% block intro %} <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"><code>XMLHttpRequest</code></a> is the plain JavaScript way to make requests. It's natively supported by all browsers.{% endblock %}
{% block script %} <script> function addSubmit(ev) { ev.preventDefault(); var request = new XMLHttpRequest(); request.addEventListener('load', addShow); request.open('POST', '{{ url_for('add') }}'); request.send(new FormData(this)); }
function addShow() { var data = JSON.parse(this.responseText); var span = document.getElementById('result'); span.innerText = data.result; }
document.forms[0].addEventListener('submit', addSubmit); </script>{% endblock %}