dph23577 2014-02-11 18: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 18: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.

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

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题