我有一个订单,在提交订单之前,用户必须通过验证码才能获得货到付款...
我正在使用jQuery检查验证码是否正确。
如果输入的验证码错误,我将不允许用户使用preventDefault提交表单,并且会提示错误。但是正确输入验证码后,它仍然不让用户提交订单。
这是我的代码...
//for captcha code
var captcha = null;
//check if captcha code is right
$("#apply_captcha").on("click", function(){
var captchaUrl = '<?php echo base_url(); ?>index.php/checkout/check_captcha/';
var captcha = $('#userCaptcha').val(); //user entered value for captcha
$.ajax({
url: captchaUrl,
type: 'POST',
data: 'captcha='+captcha,
success: function(result)
{
if(result === "success")
{
captcha = true;
$('#captcha_msg').hide();
$('#userCaptcha').css('border', '2px solid green');
}
else
{
captcha = false;
$('#captcha_msg').text("Sorry, Your captcha is wrong.");
$('#captcha_msg').css('color', '#cb2700');
}
}
});
});
$('#orderform').submit(function(e)
{
if(!pincode_available)
{
alert("Sorry, We are not supplying any product at this area right now.");
e.preventDefault();
}
else if(!captcha)
{
alert("Sorry, Your captcha is wrong");
e.preventDefault();
}
});
在“点击”功能中删除“验证码”变量的var关键字。看起来好像它在Submit函数使用全局变量时创建了一个新的局部变量。
附言:请参阅有关问题的评论,以了解我们如何得出解决方案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句