Browse Source

clean up js example

pull/2709/head
David Lord 7 years ago
parent
commit
1e84c67beb
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
  1. 2
      docs/patterns/jquery.rst
  2. 2
      examples/javascript/js_example/templates/base.html
  3. 5
      examples/javascript/js_example/templates/fetch.html
  4. 4
      examples/javascript/js_example/templates/jquery.html
  5. 5
      examples/javascript/js_example/templates/plain.html

2
docs/patterns/jquery.rst

@ -163,5 +163,5 @@ explanation of the little bit of code above:
we set earlier.
Check out the :gh:`example source <examples/javascript>` for a full
application demonstrating the jQuery on this page, as well as the same
application demonstrating the code on this page, as well as the same
thing using ``XMLHttpRequest`` and ``fetch``.

2
examples/javascript/js_example/templates/base.html

@ -23,7 +23,7 @@
<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>

5
examples/javascript/js_example/templates/fetch.html

@ -13,7 +13,7 @@
<script>
function addSubmit(ev) {
ev.preventDefault();
fetch('{{ url_for('add') }}', {
fetch({{ url_for('add')|tojson }}, {
method: 'POST',
body: new FormData(this)
})
@ -30,6 +30,7 @@
span.innerText = data.result;
}
document.forms[0].addEventListener('submit', addSubmit);
var form = document.getElementById('calc');
form.addEventListener('submit', addSubmit);
</script>
{% endblock %}

4
examples/javascript/js_example/templates/jquery.html

@ -13,7 +13,7 @@
ev.preventDefault();
$.ajax({
method: 'POST',
url: '{{ url_for('add') }}',
url: {{ url_for('add')|tojson }},
data: $(this).serialize()
}).done(addShow);
}
@ -22,6 +22,6 @@
$('#result').text(data.result);
}
$('form:first').on('submit', addSubmit);
$('#calc').on('submit', addSubmit);
</script>
{% endblock %}

5
examples/javascript/js_example/templates/plain.html

@ -12,7 +12,7 @@
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));
}
@ -22,6 +22,7 @@
span.innerText = data.result;
}
document.forms[0].addEventListener('submit', addSubmit);
var form = document.getElementById('calc');
form.addEventListener('submit', addSubmit);
</script>
{% endblock %}

Loading…
Cancel
Save