flask/examples/javascript
David Lord 22c48a738b
Merge remote-tracking branch 'origin/stable'
2024-11-13 08:43:48 -08:00
..
js_example use ruff linter and formatter 2023-11-15 12:14:37 -08:00
tests fix js example test 2024-11-01 16:44:17 -07:00
.gitignore update docs and examples for pyproject 2023-01-18 10:32:51 -08:00
LICENSE.txt update example project metadata 2024-11-01 18:00:39 -07:00
README.rst examples/javascript: replace obsolete link (#5287) 2023-10-06 17:36:39 -07:00
pyproject.toml Merge remote-tracking branch 'origin/stable' 2024-11-13 08:43:48 -08:00

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/javascript/


Install
-------

.. code-block:: text

    $ python3 -m venv .venv
    $ . .venv/bin/activate
    $ pip install -e .


Run
---

.. code-block:: text

    $ flask --app js_example 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