One of my flask URL endpoints is /register, where I gather user input and handle it as follows:
@app.route("/register", methods=["POST"])
@login_required
def register_post():
email = request.values.get("email")
username = request.values.get("username")
company_name = request.values.get("company_name")
password = request.values.get("password")
confirm_password = request.values.get("confirm_password")
messages = register(email, username, password, confirm_password, company_name)
success_message = (
"Thank you for registering with us. We will get back to you shortly."
)
print("request values: ", request.values)
print("messages: ", messages)
if (len(messages) == 1) and (messages[0] == success_message):
return jsonify({"code": 200, "message": messages[0]})
else:
return jsonify({"code": 400, "message": messages})
I want to show the messages in a browser pop-up based on the JSON data received. To access this data in JavaScript, I have the following AJAX call:
$.ajax({
url: "/register",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
alert(json);
},
error: function (e) {
alert(e);
}
});
Although the JSON object is retrieved successfully, no alerts appear on the browser. What could be the issue?
Screenshots from the developer tools can be found below:
https://i.sstatic.net/KIk5O.pngNetwork tab https://i.sstatic.net/pe1L8.png