SSM发送手机验证码——以网建SMS为例
发布日期:2021-05-06 20:00:16 浏览次数:10 分类:技术文章

本文共 1171 字,大约阅读时间需要 3 分钟。

整理一下从大二开始写的东东


后台源码链接:

在这里插入图片描述

设置用户名、密钥,在发送的时候需要携带该信息

前端代码简化后如下,提交表单我用的是ajax,如果直接提交表单记得name属性值要和后台的@RequestParam(“tel”)中的tel属性值一样,后台代码顶部链接自取。

//发送验证码 $("#send").click(function(){ var tel = $("#getTel").val(); if(checkTel("#get-chk-tel",tel)){ //alert($("#getTel").val()); $.ajax({ //这里的url和type和后台的 @RequestMapping(value="send",method=RequestMethod.POST)保持一致 type:"POST", data:{tel:$("#getTel").val()}, async:false, url:"send", success:function(result){ // alert(result); console.log(typeof(result)); if(result=="200"){ alert("发送成功,注意查收"); $("#get-chk-tel").html(""); checkCode(60); }else if(result=="2"){ $("#get-chk-tel").html("该用户不存在"); checkCode(2); } }, error:function(xhr,result){ alert(result); } }); }else{ alert("请填写好手机号码"); } }); function checkCode(time){ if(time == 0){ $('#send').removeAttr("disabled");//这个表示,从xx中移除yy属性,$(xx).remove(),移除xx元素 $('#send').html("重新发送"); }else{ time--; $('#send').attr("disabled",true); $('#send').html("倒计时"+time+"s"); setTimeout(function(){ checkCode(time); },1000); } }

效果如下:

在这里插入图片描述

上一篇:SSM搭建Bootstrap-Table[服务端分页]
下一篇:SSM的加载顺序

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年03月30日 15时36分15秒