Answer the question
In order to leave comments, you need to log in
How to display the error returned by the server (ajax post request)?
Hello. You need to register a user by sending his data to the server. The request reaches the server (there is a counter of incoming requests), but success does not work, and the error text cannot be displayed. I give the request code below, the screen displays "undefined", 0, error and an empty window, respectively:
$('.auth-button').on('click', function() {
$.ajax
({
url:url1,
type:"POST",
data:JSON.stringify({"email":$('#email').val(),"password": $('#pass').val()}),
contentType:"application/json",
dataType:"json",
success: function(){
window.location = url2;
},
error: function(xhr, status, error) {
alert(xhr.ResponseText);
alert(xhr.status);
alert(status);
alert(error);
}
});
});
Answer the question
In order to leave comments, you need to log in
do not use
alert(xhr.ResponseText);
alert(xhr.status);
alert(status);
alert(error);
console.log(xhr.ResponseText);
console.log(xhr.status);
console.log(status);
console.log(error);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question