clean up js example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 746b91d · Browse files · 5 files·+10 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+10 added−8 removed
- other:+10 added−8 removed
Provenance
- Commit
1e84c67- Tree
6b5603e- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
746b91d
5 files changed+10 added−8 removed
modified:docs/patterns/jquery.rst+1 added-1 removed
161 unmodified lines162 argument. Note that we can use the `$SCRIPT_ROOT` variable here that163 we set earlier.164 165 Check out the :gh:`example source <examples/javascript>` for a full166-application demonstrating the jQuery on this page, as well as the same166+application demonstrating the code on this page, as well as the same167 thing using ``XMLHttpRequest`` and ``fetch``.modified:examples/javascript/js_example/templates/base.html+1 added-1 removed
21 unmodified lines222324252626272829303 unmodified lines21 unmodified lines</ul><hr><p>{% block intro %}{% endblock %}</p><hr><form><form id="calc"> <label>a <input name="a"></label> <span>+</span> <label>b <input name="b"></label> <input type="submit" value="Calculate">3 unmodified linesmodified:examples/javascript/js_example/templates/fetch.html+3 added-2 removed
11 unmodified lines121314151616171819208 unmodified lines29303132333334353611 unmodified lines <script src="https://unpkg.com/whatwg-fetch@2.0.4/fetch.js"></script> <script> function addSubmit(ev) { ev.preventDefault(); fetch('{{ url_for('add') }}', { fetch({{ url_for('add')|tojson }}, { method: 'POST', body: new FormData(this) }) .then(parseJSON)8 unmodified lines var span = document.getElementById('result'); span.innerText = data.result; }
var form = document.getElementById('calc'); document.forms[0].addEventListener('submit', addSubmit); form.addEventListener('submit', addSubmit); </script>{% endblock %}modified:examples/javascript/js_example/templates/jquery.html+2 added-2 removed
11 unmodified lines12131415161617181920212223242525262711 unmodified lines function addSubmit(ev) { ev.preventDefault(); $.ajax({ method: 'POST', url: '{{ url_for('add') }}', url: {{ url_for('add')|tojson }}, data: $(this).serialize() }).done(addShow); }
function addShow(data) { $('#result').text(data.result); }
$('form:first').on('submit', addSubmit); $('#calc').on('submit', addSubmit); </script>{% endblock %}modified:examples/javascript/js_example/templates/plain.html+3 added-2 removed
10 unmodified lines111213141515161718192021222324252526272810 unmodified lines function addSubmit(ev) { ev.preventDefault(); var request = new XMLHttpRequest(); request.addEventListener('load', addShow); request.open('POST', '{{ url_for('add') }}'); request.open('POST', {{ url_for('add')|tojson }}); request.send(new FormData(this)); }
function addShow() { var data = JSON.parse(this.responseText); var span = document.getElementById('result'); span.innerText = data.result; }
var form = document.getElementById('calc'); document.forms[0].addEventListener('submit', addSubmit); form.addEventListener('submit', addSubmit); </script>{% endblock %}