Sijax stands for ‘Simple Ajax’, a Python/jQuery library designed to help you easily introduce Ajax to your application.It uses jQuery.ajax to issue AJAX requests.
In short: Sijax is a Python/jQuery library that makes AJAX easy to use in web applications.
Related course: Python Flask: Create Web Apps with Flask
Flask-Sijax
Installation
The installation of the Flask-Sijax is simple.
1 | pip install flask-sijax |
Configure SIJAX_STATIC_PATH
: Static path to the Sijax javascript file to be mirrored.The default location is static/js/simax.
1 | path = os.path.join('.', os.path.dirname(__file__), 'static/js/sijax/') |
In this folder, keep the sijax.js and json2.js files.
SIJAX_JSON_URI-URI
from which to load json2.js static files
1 | app.config['SIJAX_JSON_URI'] = '/static/js/sijax/json2.js' |
Sijax uses JSON to pass data between the browser and the server.This means that the browser requires native support JSON or JSON support is supported from the json2.js file.
Functions that are registered in this way cannot provide Sijax functionality because they cannot be accessed using the POST method by default (and Sijax uses POST requests).
View
To enable the View function to process Sijax requests, use
1 |
or use the @flash_sijax.route auxiliary
decorator such as:
1 |
Each Sijax processing function (like this) automatically receives at least one parameter, just as Python passes’self’ to the object method.The ‘obj_response’ parameter is the way the function replies to the browser.
1 | def say_hi(obj_response): |
When an Ajax request is detected, Sijax handles it like this:
1 | g.sijax.register_callback('say_hi', say_hi) |
Example
The Sijax application code for the Sijax application is the following:
1 | import os |
Related course: Python Flask: Create Web Apps with Flask