使用jQuery验证码刷新问题
我尝试在谷歌上进行研究,并在这里浏览了一些问题。我尝试了一些解决方案,但无法让它们发挥作用。
<td>
<img id="captcha" src="captcha.php" name="captcha" />
<img src="refresh.jpg" width="25" alt="" id="refresh_captcha" name="refresh_captcha" />
<input type="text" name="txtCaptcha" id="txtCaptcha" size="10" />
</td>
下面的代码不起作用:
$('.refresh_captcha').click(function(){
$('img').attr('src', 'captcha.php?cache=' + new Date().getTime());
});
我也尝试过这个:
$("#refresh_captcha").click(function() {
$("#captcha").attr("src","captcha.php?r=" + Math.random());
});
还有这个:
jQuery(function($) {
jQuery('#captcha').after("<a href=\"#\" id=\"refresh_captcha\">Refresh<\/a>");
jQuery('body').delegate('#refresh_captcha','click',function(){
jQuery.ajax({
'success':function(html){
jQuery("#captcha").attr("src",html)
},
'url':'/captcha.php?refresh=1',
'cache':false
});
return false;
});
});
有人可以帮助我吗?
I tried researching on Google and I browsed through some question here. I tried some of the solutions but I can't get them to work.
<td>
<img id="captcha" src="captcha.php" name="captcha" />
<img src="refresh.jpg" width="25" alt="" id="refresh_captcha" name="refresh_captcha" />
<input type="text" name="txtCaptcha" id="txtCaptcha" size="10" />
</td>
The code below doesn't work:
$('.refresh_captcha').click(function(){
$('img').attr('src', 'captcha.php?cache=' + new Date().getTime());
});
I also tried this:
$("#refresh_captcha").click(function() {
$("#captcha").attr("src","captcha.php?r=" + Math.random());
});
And this as well:
jQuery(function($) {
jQuery('#captcha').after("<a href=\"#\" id=\"refresh_captcha\">Refresh<\/a>");
jQuery('body').delegate('#refresh_captcha','click',function(){
jQuery.ajax({
'success':function(html){
jQuery("#captcha").attr("src",html)
},
'url':'/captcha.php?refresh=1',
'cache':false
});
return false;
});
});
Anyone can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
如果没结果2024-11-22 02:37:21
function fcapCha() {
var timestamp = (new Date()).getTime();
var newSrc = $(".capChaCaptchaImgID").attr("src").split("?");
newSrc = newSrc[0] + "?" + timestamp;
$(".capChaCaptchaImgID").attr("src", newSrc);
$(".capChaCaptchaImgID").slideDown("fast");
}
function resetCapcha() {
fcapCha();
$('.acapChapinputCaptcha').val('');
}
最良好的问候!
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您是否也尝试清空缓存? (编辑:是的,你做了...)问题是否出现在所有浏览器中?我认为您的浏览器缓存了旧图像,因为您的直接调用似乎有效。尝试用
cache: false
而不是'cache' = false
对于我来说,这个在后端使用 ajax 调用和 Java Spring 的解决方案有效:
其 HTML:
它有什么作用!?通过单击该图标,将调用函数
generateCaptcha
。请求映射调用服务器函数(在我的例子中是 java),并将新的验证码呈现到与旧验证码相同的 URL。禁用缓存并使用get
发送时间戳非常重要。在完成了一些 jQuery 魔法之后,验证码的来源将更改为图像 Url + 时间戳。希望它也适用于你的 php。
Did you try to empty the cache as well? (EDIT: yes, you did...) Did the problem appear in all browser? I reckon that your browser caches the old image, because your direct call seems to work. Try
cache: false
instead of'cache' = false
For me this solution using ajax-calls and Java Spring in backend worked:
And the HTML for that:
What does it do!? By clicking the icon the function
generateCaptcha
will be called. The request mapping called a server function (in my case java) and renders a new captcha to the same URL the old one was. Its importent to disable caching and send a timestamp with theget
. After doing that a little jQuery magic is done, the source of the captcha gonna changed to the image-Url + timestamp.Hope it'll work for you php as well.