I have made this function, that seems to work fine, but it return "#" insted of wainting for the AJAX. I have tried to remove the return call, with out look.
It need to wait until the AJAX is finish before return. The JSP is working fine.
What is wrong?
jQuery.validator.addMethod("knidExist", function(value, element) {
var valid = "#";
$.ajax({
async: false,
type: "POST",
url: "USER.jsp",
data: "knid="+value,
dataType: "html",
success: function(msg) {
// if the user exists, it returns a string "true"
if($.trim(msg) != "true") {
//return false;
valid = false; // already exists
} else {
//return true;
valid = true; // username is free to use
}
}
});
return valid;
}, 'This USER does not exist');