I have a flask URL called register, where I collect the users's input and process them like so:
@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})
Based on the messages, I would like to display the messages with a native browser pop-up. I am trying to access that JSON data in Javascript like so:
$.ajax({
url: "/register",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
alert(json);
},
error: function (e) {
alert(e);
}
});
I get the JSON object in the browser but it doesn't alert anything in the browser. what could I be doing wrong?


successorerrorcallback function invoked? What is the observed value of the parameter in that function?I passed the data from the formno, you didn't pass any data at all in the$.ajax- however, the issue is that the form submit happened, so your $.ajax did not, that's why you get no alerts