我正在使用jQuery验证插件。当我使用自定义验证和ad ajax进行某些验证时,无论输入错误还是输入正确,它都会返回相同的结果:
<script type="text/javascript">
$(document).ready(function () {
var response;
var email;
if ($("#email").val() != '')
email = $("#email").val();
//<!-- add vlidator -->
$.validator.addMethod(
"varify_user", function (value, element) {
$.ajax({
url: "welcome/verify_user",
type: "POST",
data: "{ password: '" + value + "',email: '" + email + "' }",
async: false,
contentType: 'application/json; charset=utf-8',
success: function (json) {
response = json.success;
},
dataType: 'json'
});
return response;
},
"email or password is incorrect"
);
jQuery.validator.classRuleSettings.varify_user = { varify_user: true };
$("#signIn_form").validate({
submitHandler: function (form) {
$('#register-form').submit();
}
});
});
</script>
我在razor视图中的代码是
<div data-role="fieldcontain">
<label for="email">
<em>* </em> Email: </label>
<label> <input type="text" id="email"
name="email" class="required email" /></label>
</div>
<div data-role="fieldcontain">
<label for = "password">
<em>*</em>Password:</label>
<input type="password" id="password"
name="password" class="required varify_user" />
</div>
我正在开发jQuery Mobile app请帮助我。