i want to click on href and do javascript function to post some value to python and render new template with that data, this is my code.
index.html
<!DOCTYPE html>
<html lang="en">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<body>
<a href="#" onclick="myFunction();">Click</a>
<script>
var jsvariable = 'hello world'
function myFunction(){
$.ajax({
url: "/getvalue",
type: "post", //send it through get method
data:{'jsvalue': jsvariable},
})
}
</script>
</body>
</html>
server.py
from flask import Flask, render_template, request, url_for
app = Flask(__name__)
@app.route('/', methods=['GET','POST'])
def index():
return render_template('index.html')
@app.route('/getvalue', methods=['GET','POST'])
def getvalue():
data = request.form['jsvalue']
print(data)
return render_template('index2.html', data=data)
if __name__ == "__main__":
app.run(debug=True)
Now the data that pass from ajax function to getvalue() in python that work properly but it not render to new template, so how can i fix that.