刷新验证码图像 jquery codeigniter

瓦哈兹

我的刷新验证码按钮有问题,当我重新加载页面后单击该按钮时,它只能工作一次。我不知道是我错了还是我错过了其他东西。

我尝试使用 jquery 刷新验证码,因为效率更高。

这是我的一段代码:

控制器

public function refresh_login(){
    // Captcha configuration
    $config = array(
        'img_path'      => 'captcha_images/',
        'img_url'       => base_url().'captcha_images/',
        'img_width'     => '100',
        'img_height'    => '30',
        'word_length'   => '4',
        'font_size'     => '16'
    );
    $captcha = create_captcha($config);

    // Unset previous captcha and store new captcha word
    $this->session->unset_userdata('captchaCode');
    $this->session->set_userdata('captchaCode',$captcha['word']);

    // Display captcha image
    echo $captcha['image'];
}

查询

$( document ).ready( function () {
  var base_url = '<?php echo base_url(); ?>';
     $('.reload-captcha').click(function(event){
         event.preventDefault();
         $.ajax({
             url:base_url+'index.php/auth/refresh_login',
             success:function(data){
                 $('.captcha-img').replaceWith(data);
             }
         });            
      });

看法

<form action="<?php echo base_url(); ?>index.php/auth/login/" id="login-form" method="post">
  <div class="form-group has-feedback">
    <input type="text" class="form-control" placeholder="Username" id="username" name="username" required>
    <span class="glyphicon glyphicon-user form-control-feedback"></span>
  </div>
  <div class="form-group has-feedback">
    <input type="password" class="form-control" placeholder="Password" id="password" name="password" required>
    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
  </div>
  <div class="form-group">
    <p id="captImg" class="captcha-img"><?php echo $captchaImg; ?></p>
    <input type="text" class="form-control" name="captcha" placeholder="Captcha" style="margin-bottom: 5px"/>
    <a href="#" class="reload-captcha refreshCaptcha btn btn-info btn-sm" ><i class="glyphicon glyphicon-refresh"></i></a>
  </div>
  <div class="row">
    <!-- /.col -->
    <div class="col-xs-8">
          <label><a href="#"><u>Forgot your password?</u></a></label>
    </div>
    <div class="col-xs-4 pull-right">
      <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
    </div>
    <!-- /.col -->
  </div>
</form>
Swarna Sekhar Dhar

发生了什么样的问题???尝试 :

$('.captcha-img').attr("src", data);

代替:

$('.captcha-img').replaceWith(data);

并添加

dataType: "text",  
  cache:false,

如下 :

$.ajax({
             url:base_url+'index.php/auth/refresh_login',
             dataType: "text",  
             cache:false,
             success:function(data){
                $('.captcha-img').attr("src", data);
             }
         }); 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章