2016-04-06 76 views
0

我使用默认的验证码窗口小部件和高级Yii2模板。如果验证失败,我想刷新验证码图片。我尝试使用前面所述的触发器,但我希望在验证码时刷新图像失败。yii2验证失败时刷新验证码

<?= $form->field($model, 'captcha')->widget(Captcha::classname(), [ 'template' => '{image} <a href="javascript:;" onclick="captchRef()" >Refresh</a>{input}', ])?> 

<script> 
    function captchRef(){ 
     $("img[id$='-captcha-image']").trigger('click'); 
    } 
    $(document).ready(function(){ 
     jQuery.ajax({ 
      'success': function(html){ 
       jQuery("#yw0").attr("src",html) 
      }, 
      'url':'captcha?refresh=1', 
      'cache':false 
     }); 
     return false; 
    }); 
</script> 
+0

到目前为止尝试过的? –

+0

在我的视图文件中: field($ model,'captcha') - > widget(Captcha :: classname(),[ 'template'=>'{image} Refresh {input}', ])> Anonymous

回答