Using Flask Return To Modify A Webpage
I have the simplest flask app: app = Flask(__name__) @app.route('/python/', methods = ['GET','POST']) def index(): return 'Hello World' if __name__ == '__main__': app.run(d
Solution 1:
see the code below and review the XMLHttpRequest.onreadystatechange for detail
<script>functionmyFunction() {
var xhttp = newXMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === XMLHttpRequest.DONE) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", "http://127.0.0.1:5000/python/", true);
xhttp.send();
}
</script>
no cors issue if you send the html from your flask app see the example code, you need to import render_template from flask.
@app.route('/')defhello_world():
return render_template('index.html')
Post a Comment for "Using Flask Return To Modify A Webpage"