javascript
- Folder:js_example
- Folder:tests
- File:.gitignore
- File:LICENSE.rst
- File:MANIFEST.in
- File:README.rst
- File:setup.cfg
- File:setup.py
README.rst
JavaScript Ajax Example
Demonstrates how to post form data and process a JSON response using
JavaScript. This allows making requests without navigating away from the
page. Demonstrates using |fetch|, |XMLHttpRequest|, and
|jQuery.ajax|. See the Flask docs about JavaScript and Ajax.
.. |fetch| replace:: fetch
.. _fetch: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
.. |XMLHttpRequest| replace:: XMLHttpRequest
.. _XMLHttpRequest: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
.. |jQuery.ajax| replace:: jQuery.ajax
.. _jQuery.ajax: https://api.jquery.com/jQuery.ajax/
.. _Flask docs: https://flask.palletsprojects.com/patterns/jquery/
Install
.. code-block:: text
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install -e .
Run
.. code-block:: text
$ export FLASK_APP=js_example
$ flask run
Open http://127.0.0.1:5000 in a browser.
Test
.. code-block:: text
$ pip install -e '.[test]'
$ coverage run -m pytest
$ coverage report