我有一个输入,在输入每个字符后检查密码。这增加了对每个键的 POST 检查。
确认密码检查后,将启用提交按钮,当您单击此按钮时,它会通过 ajax 将详细信息发送到 php。但它实际上触发的次数与按键检查的次数相同。有没有办法限制只开火一次?如果我的密码中有 6 个字符,那么它会完成 6 次 keyup 检查和 6 次点击更新。
Keyup密码检查
$('input[name=currentpassword]').keyup(function(){
var currentcheck = $(this).val();
var dataString='thisConfirm='+ currentcheck +'&userid='+$('input[name=userid]').val();
setTimeout(function(){
PasswordChecking = $.ajax({
type:"POST",
url:"/assets/inc/password-check.php",
data:dataString,
dataType:'html',
context:document.body,
global:false,
async:true,
success:function(data){
//return data
var PasswordChecking="1";
console.log(PasswordChecking);
console.log("here you would decide on data for valiadation success");
checkconfirms(emailconfirm, passconfirm, PasswordChecking);
}
}).responseText;
}, 1000);
});
位于 checkconfirms 函数内的 jQuery 更新按钮
$('input[name=updatedetails]').click(function(){
var newEmailValue = $('input[name=newemailconfirm]').val();
var accountID = $('input[name=userid]').val();
var dataString='email='+ newEmailValue +'&userid='+accountID;
$.ajax({
type:"POST",
url:"/assets/inc/user-change-email.php",
data:dataString,
dataType:'html',
context:document.body,
global:false,
async:false,
success:function(data){
var overlay = $("<div/>").addClass("overlay");
var logindialog = $("<div/>").addClass("popup-login");
$("body").append(overlay);
$("body").append(logindialog);
$(".popup-login").prepend('<p><label for="email">Email</label><input type="text" name="reloginemail" id="email"></p><p><label for="password">Password</label><input type="password" name="reloginpass" id="password"></p><input type="button" name="relogindude" value="sign in">');
$(".overlay").fadeIn();
$(".popup-login").fadeIn();
// Once the pop up is created this enable the click function which will enable the ajax form check.
$('input[name=relogindude]').click(function(){
var email = $('input[name=reloginemail]').val();
var password = $('input[name=reloginpass]').val();
var dataStringed='newemail='+ email +'&newpassword='+password;
$.ajax({
type:"POST",
url:"/assets/inc/login.php",
data:dataStringed,
success:function(data){
window.location.reload();
}
});
});//End relogindude click function
}
});//End updatedetails click function