In my Flask applòication, I am sending an error message as response from an AJAX submit funciton, this way:
return jsonify(message='An error occurred!'),500
In the client I have this function:
$("#submit_button").click(function(){
.....
$.ajax({
url: '/',
data: $("#startcopy").serialize(),
type: "POST",
success: function(response) {
console.log(response);
$("#wait").hide();
alert(response);
},
error: function(request,status, message) {
console.log(request);
$("#wait").hide();
alert("Error\n"+message);
}
});
}
});
But I can't get the error message displayed in the alert box. Where am I wrong?
In the error callback, the response body will be a property of the first argument, which in the jQuery docs is named jqXHR and in your code is named request.
Since you returned JSON, try this: alert("Error\n" + request.responseJSON.message);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With