Why ajax method calls error function?
<p>I have jquery script, which sends ajax request to servlet. It works, it posts text data to servlet <em>correctly</em>, but then it calls error function, instead of success function(I checked, servlet send back to ajax <em>not null</em> string).</p>

<p>Why ajax method calls error function?</p>

<p>Here's code of script</p>

<pre><code>    $(document).ready(function () {
        $("#login-button").click(function () {
            var userPassword = $("input#userPassword").val();
            var userLogin = $("input#userLogin").val();
            $.ajax({
                type: "POST",
                url: "http://localhost:8181/library/login",
                data: {login: userLogin, password: userPassword},
                dataType: "text",
                success: function (data) {
                    if (data == "1") {
                        document.location.href = "http://localhost:8181/library/workshop.html";
                    }
                    if (data == "2") {
                        document.location.href = "http://localhost:8181/library/library.html";
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("Error report\n" + "jqXHR = " + jqXHR + "\n" + "textStatus = " + textStatus + "\n" +
                            "errorThrown =  " + errorThrown);
                }
            });
        });
    });
</code></pre>

<p>Here's code of servlet</p>

<pre><code>    public class LoginServlet extends HttpServlet {

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();
    String login = request.getParameter("login");
    String password = request.getParameter("password");
    SocketConnection.output.println("log_in " + login + " " + password);
    out.print(SocketConnection.input.readLine());
    out.close();
        }

    }
</code></pre>

<p>The textStatus value is <code>error</code>, the errorThrown value is void, in the error report.</p>