dph23577 2014-02-11 10:07
浏览 59
已采纳

重新加载Captcha不适用于jquery PHP

I am using jquery php captcha in magento.Captcha is getting generated fine but I also want to refresh it but not getting how to do it.Here is my code which I used.

HTML Code

    <span id="reload_captcha_span"><img id="captcha_image" src="<?php echo $this->getUrl('helloworld/index/captcha'); ?>"/></span>
<span id="reload_captcha">reload</span>

JQuery Code

jQuery('#reload_captcha').click(function(){
                jQuery.ajax({
                        url: '<?php echo $this->getUrl('helloworld/index/captcha'); ?>',
                        success:function(data){
                            jQuery('#reload_captcha_span').html("");
                            jQuery('#reload_captcha_span').html(data);
                        }
                    }); 
            });

PHP Code

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);

In response I am getting unknown data may be that is image itself.

Please help me.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • doutang6130 2014-02-11 10:40
    关注

    Try this:

    jQuery('#reload_captcha').click(function(){
        var d = new Date();
        jQuery('#captcha_image').attr('src', '<?=$this->getUrl('helloworld/index/captcha')?>?'+d.getTime());
    });
    

    To fetch the same image url, but we add a random (time) parameter, so it's not fetched from the cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部