I have an ajax request that forwards the login and password to the servlet. The servlet receives them, but at the same time, the error function is launched in ajax , which, if you believe the documentation, works if the request fails. Why it happens?

Request code

 $(document).ready(function(){ $("#login-button").click(function(){ var userPassword = $("input#userPassword").val(); var userLogin = $("input#userLogin").val(); var dataString = "log_in " + userLogin + " " + userPassword; $.ajax({ type: "POST", url: "http://localhost:8181/library/login", data: { login: userLogin, password: userPassword }, dataType: "text", success: function(data) { alert("Welcome!"); }, error: function(jqXHR,textStatus,errorThrown) { alert("Wrong login or password"); } }); }); }); 
  • And what does the servlet return? - zb '
  • see the value of textStatus, errorThrown well, and in general errors in the consley - Grundy
  • In textStatus, the error value, in errorThrown is empty - will_hunting
  • The servlet returns a text string - will_hunting

0