$.validator.addMethod("checkUsername",
function(value, element){
var test; //we want to use this test is like boolean variable
$.ajax({
type:"GET",
data: 'name='+ value,
url: "master/ValidationDepartment.jsp",
success: function(response){
test = true; //assign this value is true
},
error: function() {
test = false; //assign this value is false
}
});
//alert(test); // bt now this time test value is undifined
return test;
},
"Departmentname Already Exists."
);
});
我也试过了var test = true
。如果我们test = true
每次都声明它的值为真。