/** * 验证码相关js * * @author CaiAoLin * @date 2017/10/13 * @version */ $(document).ready(function() { // 载入时先获取相关参数 $.ajax({ url: '/captcha', type: 'get', data: '', timeout: 5000, error: function() { $("#captcha-box").html('验证码加载失败'); }, beforeSend: function() { $("#captcha-box").html('正在加载验证码'); }, success: function(response) { $("#captcha-box").html(''); if (response.success === 0) { alert('验证码初始化失败!'); return false; } initGeetest({ // 以下配置参数来自服务端 SDK gt: response.gt, challenge: response.challenge, offline: !response.success, new_captcha: response.new_captcha, width: '100%' }, function (captchaObj) { captchaObj.appendTo('#captcha-box'); captchaObj.onSuccess(function () { $(".btn-area").slideDown("fast"); }); }) } }); });