flask/examples/javascript
David Lord ab1fbef29a
prefer --app over FLASK_APP in docs
2022-06-17 09:26:26 -07:00
..
js_example remove javascript fetch polyfill 2022-06-08 07:30:29 -07:00
tests remove javascript fetch polyfill 2022-06-08 07:30:29 -07:00
.gitignore add javascript ajax example 2018-04-12 11:06:02 -07:00
LICENSE.rst move package metadata to setup.cfg 2020-04-04 14:50:21 -07:00
MANIFEST.in move package metadata to setup.cfg 2020-04-04 14:50:21 -07:00
README.rst prefer --app over FLASK_APP in docs 2022-06-17 09:26:26 -07:00
setup.cfg remove javascript fetch polyfill 2022-06-08 07:30:29 -07:00
setup.py move package metadata to setup.cfg 2020-04-04 14:50:21 -07: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/jquery/


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