您好我正在尝试在JQuery.Validation的submitHandler中调用我的控制器/动作MVC并且它不能在那里工作,我可以使它工作在cshtml中的事件submitHandler之外创建$ ajax工作,但为什么这里不起作用?我收到一个错误:ajaxSubmit不是firebug中的函数。为什么?感谢
var form = $('.handlevalidation');
var error = $('.alert-danger', form);
var success = $('.alert-success', form);
form.validate({
errorElement: 'span', //default input error message container
errorClass: 'help-block help-block-error', // default input error message class
focusInvalid: false, // do not focus the last invalid input
ignore: "", // validate all fields including form hidden input
messages: {
'Employee.Username': { remote: "This Username was already taken." },
'Employee.Barcode': { remote: "This Barcode is already in use." }
},
rules: {
// ** RULES **
'Employee.Username': {
minlength: 3,
maxlength: 55,
required: true,
remote: { url: baseUrl + 'Employees/CheckDuplicatedUsername', type: "post", data: { username: function () { return $('#Employee_Username').val(); }, id: function () { return $('#Employee_Id').val(); } } }
},
'Employee.Password': { minlength: 3, maxlength: 55, required: false },
'Employee.Barcode': {
maxlength: 255,
required: false,
remote: { url: baseUrl + 'Employees/CheckDuplicatedBarcode', type: "post", data: { barcode: function () { return $('#Employee_Barcode').val(); }, id: function () { return $('#Employee_Id').val(); } } }
},
'Employee.FirstName': { minlength: 3, maxlength: 55, required: true },
'Employee.LastName': { minlength: 3, maxlength: 55, required: false },
'Employee.EmailAddress': { required: false, email: true },
'Password': { required: true, minlength: 3, maxlength: 10 },
'ConfirmPassword': { required: true, minlength: 3, maxlength: 10, equalTo: "#Password" }
},
invalidHandler: function (event, validator) { //display error alert on form submit
success.hide();
error.show();
Metronic.scrollTo(error, -200);
},
highlight: function (element) { // hightlight error inputs
$(element)
.closest('.form-group').addClass('has-error'); // set error class to the control group
},
unhighlight: function (element) { // revert the change done by hightlight
$(element)
.closest('.form-group').removeClass('has-error'); // set error class to the control group
},
success: function (label) {
label
.closest('.form-group').removeClass('has-error'); // set success class to the control group
},
submitHandler: function (form) {
success.show();
error.hide();
$form.ajaxSubmit({
type: 'post',
url: baseUrl + 'Employees/UpdatePassword',
data: $form.serialize(),
success: function (response) {
if (response == 'success') {
var $target = $($form.attr('data-target'));
alert('Password changed successfully!');
$target.modal('hide');
} else {
error.show();
}
}
});
}
});