I have made a post request from JavaScript to my Flask python code through ajax, but I cannot find a way to return the data in a way that will allow me to get is again through the JavaScript. What I'm trying to do is send data to the Flask server, and return other data back to the JavaScript.
I have tried to use a success: function but it doesn't seem to work and seen as a Uncaught SyntaxError: Unexpected identifier
The relevant part of the JavaScript code:
$.ajax({
type: "POST",
url: "/login",
data: JSON.stringify(login_info),
contentType: "application/json",
dataType: 'json'
success: function(data){
console.log(data);
}
});
The data im trying to get is the results from the code below V
The Flask(python) code:
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == "POST":
user_info = request.get_json()
print(user_info)
results = {'processed': 'true'}
return jsonify(results)
else:
return render_template("login.html")