【问题标题】:Refresh captcha image?刷新验证码图片?
【发布时间】:2020-05-01 19:55:54
【问题描述】:

我有一个动作方法返回一个图像文件captcha,我不知道如何实现一个按钮来刷新这个captcha。我想我应该使用Jquery,因为我不想重新加载此页面,但我不知道如何实现

这是我的 Action 方法:

public ActionResult Index()
    {
        var captcha = new DemoMVC2112.Models.CenterCaptcha();
        Session["captcha"] = captcha.Text;
        return File(captcha.ImageAsByteArray, "image/png");
    }

视图中的 Div 验证码:

 <div class="captchaImage">
  <img src='@Url.Action("Index", "CaptchaImage")' id="captchaImage" /> <button id="Refresh_Captcha">ReFresh CaptCha</button>
</div>

【问题讨论】:

    标签: jquery asp.net-mvc captcha


    【解决方案1】:

    尝试像这样添加,我希望这能解决您的问题

    然后通过添加日期来绑定验证码以刷新​​验证码的内容

       function reloadCaptcha()
       {
         document.getElementById('captchaImage').src = 
         document.getElementById('captchaIMage').src+ '?' new Date().getTime();
       }
    

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 2016-01-22
      • 1970-01-01
      • 2016-09-30
      • 2012-04-26
      • 2013-08-23
      • 2011-11-12
      • 1970-01-01
      • 2012-12-17
      相关资源
      最近更新 更多