forked from orbit-oss/flask
add javascript ajax example
This commit is contained in:
parent
d8bf589d48
commit
fce1885f76
21 changed files with 341 additions and 13 deletions
27
examples/javascript/js_example/templates/jquery.html
Normal file
27
examples/javascript/js_example/templates/jquery.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block intro %}
|
||||
<a href="https://jquery.com/">jQuery</a> is a popular library that
|
||||
adds cross browser APIs for common tasks. However, it requires loading
|
||||
an extra library.
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<script>
|
||||
function addSubmit(ev) {
|
||||
ev.preventDefault();
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '{{ url_for('add') }}',
|
||||
data: $(this).serialize()
|
||||
}).done(addShow);
|
||||
}
|
||||
|
||||
function addShow(data) {
|
||||
$('#result').text(data.result);
|
||||
}
|
||||
|
||||
$('form:first').on('submit', addSubmit);
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue