jquery验证和php验证码问题 [英] jquery validate and php captcha issue
问题描述
我的验证码字段
<p style="height:30px;"><img id="captcha" src="includes/secureimage/securimage_show.php?sid=<?php echo md5(time()); ?>" alt="CAPTCHA Image" />
<a tabindex="-1" style="border-style: none; margin-left:5px;" href="#" title="Refresh Image" onclick="document.getElementById('captcha').src = 'includes/secureimage/securimage_show.php?sid=' + Math.random(); return false"><img src="images/refresh.png" alt="Reload Image" onclick="this.blur()" style="vertical-align: top; border:0;" /></a></p></div>
<p><label for="seccode">Verification Code:<span class="important">*</span></label><input id="seccode" type="text" name="seccode" size="10" class="required" /></p>
我的jquery验证验证码的插件代码
my jquery validate plugin code for captcha
seccode: {
required: true,
remote: {
url: "checkuser.php",
type: "post",
data: {
seccode: function() {
//alert($("#seccode").val());
return $("#seccode").val();
}
}
}
}
my php
if($_POST['seccode'])
{
$securimage = new Securimage();
return $securimage->check($_POST['seccode']);
}
我正在使用securimage进行验证码。验证码的必要条件的消息正在运行。但是远程条件不起作用。当然我已经在php中包含了必需的类文件,并且还在php文件的开头启动了session_start()。
i am using securimage for captcha. message for required condition for captcha is working. but remote condition is not working. Ofcourse i have included required class file in php and also started session_start() in the start of php file.
[注意]
错误现在消失了。现在有了新的东西。第一次验证码在我关注时工作,但之后它继续回调每次更改的验证方法..请参阅下面的firebug输出...
[note] the error gone now. something new comes now. First time the captcha works when i focus out, but after that it continues to callback the validation method on each change.. see the firebug output below...
GET http://localhost:8080/property/html/captcha.php?seccode=pzubwg
GET http://localhost:8080/property/html/captcha.php?seccode=pzubwg
200 OK
36ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=l
GET http://localhost:8080/property/html/captcha.php?seccode=l
200 OK
39ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=ln
GET http://localhost:8080/property/html/captcha.php?seccode=ln
200 OK
41ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnr
GET http://localhost:8080/property/html/captcha.php?seccode=lnr
200 OK
36ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
200 OK
38ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
200 OK
32ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgue
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgue
200 OK
25ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgu
200 OK
34ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
GET http://localhost:8080/property/html/captcha.php?seccode=lnrg
200 OK
40ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgv
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgv
200 OK
42ms
jquery.min.js (line 140)
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgve
GET http://localhost:8080/property/html/captcha.php?seccode=lnrgve
200 OK
37ms
推荐答案
基本上,当你的jquery验证验证码时,验证码代码会在验证发生的同一个函数中被销毁。这就是我遇到问题的原因。一旦再次刷新验证码,代码就可以正常工作。
Basically when your jquery validates the captcha code, the captcha code is destroyed in the very same function where the validation occurs. Thats why i was getting the problem. The code works fine once you refresh the captcha again.
这篇关于jquery验证和php验证码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!