jQuery validation error message won't hide for remote rule

72 views Asked by At

I am trying to print an error message when email is taken Using Jqueryvalidation but when I enter email which is not taken, the error message won't go away.

please help!

html

<form id="valid" method="post">
        <input type="email" name="emailinput">
        <br><br>
        <input type="submit">
    </form>

javascript

$("#valid").validate({

            rules : {
                emailinput:{
                    minlength:4,
                    required:true,
                    remote: {
                    type: "POST",
                    url: 'UserValidation'//servlet
                    }
                }

                }
    })

    })

servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uname = request.getParameter("emailinput");

        boolean status = user_data.isEmailAvailable(uname);
        System.out.println(status);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        if(status)
        {

            response.getWriter().println("\"\"");
        }
        else
            response.getWriter().println("{\"true\"}");

    }

I am sure about the servlet, it is working as expected

enter image description here

1

There are 1 answers

1
Nathan Hawks On

You need to use the submitHandler option to define a function that you'll run whenever the inputs are valid.

For readability, you can also use the invalidHandler to house your code for handling bad inputs. (TBH I can't even see how you're handling the response from rules.emailInput.remote, but then the .remote option isn't covered in the docs I found.)