我正在尝试使用jquery验证从数据库中检查旧密码。其完美的工作, 但是我的问题是jQuery.validator.addMethod()对keyup进行检查,然后处理时间非常慢,因为每次调用它的方法。
我的代码是:
$('document').ready(function(){
/**Check old password */
jQuery.validator.addMethod("checkoldpassword",function(value,element,param){
var old_pass = $("#old").val();
var input_old_password = $("#old_password").val();
var url = "{{url('admin/checkoldpassword')}}";
var res = '';
$.ajax({
type : "POST",
url : url,
data : {old_pass , input_old_password },
async : false,
success : function(data) {
if(data == 'true') {
return true;
} else {
return false;
}
}
});
return res;
},"Please enter correct old password value");
-----------------------------------------------------------------------
validator = $("#changepassword_form").validate({
rules: {
new_password : {
required : true,
minlength : 8
},
confirm_password : {
required : true,
minlength : 8,
equalTo : "#new_password"
},
old_password : {
required : true,
checkoldpassword :true
}
},
----------------------------------------------------------------------------
在控制器中
public function checkoldpassword(Request $request)
{
$input = $request->all();
if((\Hash::check($input['input_old_password'],$input['old_pass']))) {
return 'true';
}
return 'false';
}
答案 0 :(得分:0)
在此doneTyping()函数中使用ajax。
//setup before functions
var typingTimer; //timer identifier
var doneTypingInterval = 5000; //time in ms, 5 second for example
var $input = $('#myInput');
//on keyup, start the countdown
$input.on('keyup', function () {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
});
//on keydown, clear the countdown
$input.on('keydown', function () {
clearTimeout(typingTimer);
});
//user is "finished typing," do something
function doneTyping () {
//do something
}