1

So I am having an issue that my ajax is going directly to the error call, I understand that I don't have anything in my success call however I would expect the page to return the messages from my servlet when correct or incorrect data is given. the popup dialog returns this message

error: [object Object] status: error er:

ajax-

function sendAjax(){
    var article = new Object();
    article.username = $('#username').val();
    article.password = $('#password').val();        
    $.ajax({
        url: 'http://localhost:8080/FishingTrax/LoginServlet',
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(article),
        contentType: 'application/json',
        mimeType: 'application/json',

        success: function (data) {

        },
        error:function(data,status,er) {
            alert("error: "+data+" status: "+status+" er:"+er);

        }
    });
    return false;
};

servlet-

response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if(databaseConnection.checkUser(username, password))
    {
        RequestDispatcher rs = request.getRequestDispatcher("Welcome");
        rs.forward(request, response);
    }
    else
    {
        out.println("Username or Password incorrect");
        RequestDispatcher rs = request.getRequestDispatcher("login.html");
        rs.include(request, response);
    }
}
2
  • 2
    There's a reason the error method takes a status parameter. Its impossible to troubleshoot without knowing what status was returned. Commented Apr 23, 2014 at 20:09
  • this was the message returned error: [object Object] status: error er: Commented Apr 24, 2014 at 8:25

1 Answer 1

1

In your ajax request you expect the sever to send json data. But as far as i can see your server is not providing json but html data. That should cause the error.

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

Comments

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.