Answers for "how to get data in flask from ajax"

1

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")

# This function gets param1 from url yourflaskroot/getdata
# which was the url set in ajax code and return param1 back to it
# you can write a simple ajax code to test it out
@app.route("/getdata")
def myFunction():
  	# Fill parameter with the argument sent from ajax
	parameter = request.args.get('param1')
    # Send parameter as an argument to ajax
	return f"the returned data from python is : {parameter}"


if __name__ == "__main__":
	app.run(debug=True)
Posted by: Guest on March-25-2021

Code answers related to "how to get data in flask from ajax"

Python Answers by Framework

Browse Popular Code Answers by Language