phoneCode.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //注册获取验证码
  2. $("#getverificode").click(function () {
  3. var mobileValue = $.trim($('#telephone').val());
  4. if (mobileValue == '') {
  5. qsToast({type:2,context: '请输入手机号码'});
  6. return false;
  7. };
  8. if (mobileValue != "" && !regularMobile.test(mobileValue)) {
  9. qsToast({type:2,context: '请输入正确的手机号码'});
  10. return false;
  11. }
  12. $.ajax({
  13. headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
  14. url: codeUrl,
  15. type: 'POST',
  16. dataType: 'json',
  17. data: {
  18. mobile:mobileValue,
  19. type:1,
  20. },
  21. success: function (result) {
  22. console.log(result);
  23. // 开始倒计时
  24. var countdownZZ = 60;
  25. function settime() {
  26. if (countdownZZ == 0) {
  27. $('#getverificode').html('获取验证码');
  28. $('#getverificode').attr("disabled",false);
  29. countdownZZ = 100;
  30. return;
  31. } else {
  32. $("#getverificode").css('font-size','18px');
  33. $('#getverificode').html('重新发送' + countdownZZ + '秒');
  34. $('#getverificode').attr("disabled",true);
  35. countdownZZ--;
  36. }
  37. setTimeout(function() {
  38. settime()
  39. },1000)
  40. }
  41. settime();
  42. },
  43. error: function (errorData) {
  44. if (errorData.status==422) {//验证错误;
  45. $.each(errorData.responseJSON.errors,function (key,val) {
  46. qsToast({type:2,context: val[0]});
  47. });
  48. }
  49. else if(errorData.status==400) {//业务错误
  50. qsToast({type:2,context:errorData.responseJSON.message});
  51. }
  52. }
  53. })
  54. });