ajax using flask code example
Example 1: how to create ajax api in flask
<script type=text/javascript src="{{
url_for('static', filename='jquery.js') }}"></script>
Example 2: how to get data in flask from ajax
from flask import *
app = Flask(__name__)
@app.route("/", methods=["POST", "GET"])
def home():
return render_template("index.html")
@app.route("/getdata")
def myFunction():
parameter = request.args.get('param1')
return f"the returned data from python is : {parameter}"
if __name__ == "__main__":
app.run(debug=True)