captcha.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * 验证码相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/10/13
  6. * @version
  7. */
  8. $(document).ready(function() {
  9. // 载入时先获取相关参数
  10. $.ajax({
  11. url: '/captcha',
  12. type: 'get',
  13. data: '',
  14. timeout: 5000,
  15. error: function() {
  16. $("#captcha-box").html('验证码加载失败');
  17. },
  18. beforeSend: function() {
  19. $("#captcha-box").html('正在加载验证码');
  20. },
  21. success: function(response) {
  22. $("#captcha-box").html('');
  23. if (response.success === 0) {
  24. alert('验证码初始化失败!');
  25. return false;
  26. }
  27. initGeetest({
  28. // 以下配置参数来自服务端 SDK
  29. gt: response.gt,
  30. challenge: response.challenge,
  31. offline: !response.success,
  32. new_captcha: response.new_captcha,
  33. width: '100%'
  34. }, function (captchaObj) {
  35. captchaObj.appendTo('#captcha-box');
  36. captchaObj.onSuccess(function () {
  37. $(".btn-area").slideDown("fast");
  38. });
  39. })
  40. }
  41. });
  42. });