Answer the question
In order to leave comments, you need to log in
How to send a POST request correctly?
The POST request
is not always sent either nothing comes or None as in this case:
html
<form action="" method="post" name="sentmol" style="display: none" value="{{ sendit }}"></form>
var checkExist = setInterval(function() {
if (document.querySelector("#output > pre")) {
console.log(document.querySelector("#output > pre").innerHTML);
var sendit = document.querySelector("#output > pre").innerHTML;
var xhr = new XMLHttpRequest()
xhr.open("POST", '/', true)
xhr.send(sendit);
clearInterval(checkExist);
}
}, 100);
@app.route('/create', methods=['GET', 'POST'])
def create():
if request.method == 'POST':
new = request.json
print('my data = ', new)
Answer the question
In order to leave comments, you need to log in
example for passing over JSON
Request:
Server-side implementation:
@app.route("/", methods=['GET', 'POST'])
def index():
if request.method == "POST":
name = request.json
print(name)
return "Hello"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question