3

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?

1 Answer 1

3

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);

Sign up to request clarification or add additional context in comments.

1 Comment

Great! Shame on me for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.