我有一個應用程序表單,我需要使用jquery驗證驗證碼。如果輸入的驗證碼不正確,那麼顯示的提示框請再次輸入驗證碼輸入的驗證碼是錯誤的。我怎樣才能使用jquery?請幫幫我。我是jquery的新手。使用jquery驗證驗證碼
下面是代碼:從https://code.google.com/p/recaptcha4j/downloads/list
<%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %>
<form action="." method="post">
<div class="loginbox">
<c:set var="PUBLIC_KEY" scope="page" value="${requestScope.properties.get('PUBLIC_KEY')}" />
<c:set var="PRIVATE_KEY" scope="page" value="${requestScope.properties.get('PRIVATE_KEY')}" />
<% ReCaptcha c = ReCaptchaFactory.newSecureReCaptcha((String)pageContext.getAttribute("PUBLIC_KEY"), (String)pageContext.getAttribute("PRIVATE_KEY"), false);
out.print(c.createRecaptchaHtml("errorMessage","blackglass", 2)); %>
<button type="submit">Submit</button>
</div>
</form>
$(function() {
$("#XISubmit").click(function(){
event.preventDefault()
val=$('#vercode').val()
$.ajax({
type:"post",
url:"verify-captcha.php",
data:{'code':val},
success:function(data){
if(data=='false'){
alert('Re-enter Captcha, You Entered wrong captcha code')
$("#cap").html("<img src='captcha_image.php'>"); }
else{
document.getElementById("XIForm").submit();
}
}
});
});
});
document.getElementById("XIForm").submit();
});
Html page :
<label>Security Validation</label>
<span><img src="captcha.php"></span><input type="text" name="vercode" id="vercode" size="10" style="margin-top: -1px; float: left; width: 115px; margin-right: 12px;"></li><div id="msg"></div>
captcha.php
<?php
session_start();
$ranStr = md5(microtime());
$ranStr = substr($ranStr, 0, 6);
$_SESSION['cap_code'] = $ranStr;
$newImage = imagecreatefromjpeg("cap_bg.jpg");
$txtColor = imagecolorallocate($newImage, 0, 0, 0);
imagestring($newImage, 5, 5, 5, $ranStr, $txtColor);
header("Content-type: image/jpeg");
imagejpeg($newImage);
?>
verify-captcha.php
<?php
session_start();
if ($_POST["code"] != $_SESSION["cap_code"] || $_SESSION["cap_code"]=='') {
echo 'false';
}else{
echo 'true';}
它使用jQuery,你正在嘗試做的,因爲那麼就可以繞過所以這將是無用的不做......此驗證必須通過目標資源進行 –
現在發生了什麼 –
@ArunPJohny,你的意思是,可以修改JS文件嗎? –