适合自己的 ● 才是最好的 新闻动态,洞悉互联网前沿资讯,探寻网站营销规律
当前位置:网站首页 >> 网站制作
pbootcms使用Ajax无刷新提交留言及表单
日期:2021-10-14 11:22:14 来源:合肥良马网络科技有限公司 官网:https://www.hflmwl.com/ 阅读:1345次
留言表单
1 <form onsubmit="return submsg(this);">
2     联系人<input type="text" name="contacts" required id="contacts">
3     手 机<input type="text" name="mobile" required id="mobile">
4     内 容<textarea name="content" id="content"></textarea>
5     验证码<input type="text" name="checkcode" required id="checkcode">
6     <img title="点击刷新" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" />
7     <button type="submit">提交留言</button>
8 </form>

Ajax提交
01 <script>
02 //ajax提交留言,由于涉及到提交地址标签的解析,JS需要放在html文件中
03 function submsg(obj){
04   var url='{pboot:msgaction}'; //如果是自定义表单则使用地址{pboot:form fcode=*}
05   var contacts=$(obj).find("#contacts").val();
06   var mobile=$(obj).find("#mobile").val();
07   var content=$(obj).find("#content").val();
08   var checkcode=$(obj).find("#checkcode").val();
09    
10   $.ajax({
11     type'POST',
12     url: url,
13     dataType: 'json',
14     data: {
15         contacts: contacts,
16         mobile: mobile,
17         content: content,
18         checkcode: checkcode
19     },
20     success: function (response, status) {
21       if(response.code){
22          alert("谢谢您的反馈,我们会尽快联系您!");
23          $(obj)[0].reset();
24       }else{
25          alert(response.data);
26       }
27     },
28     error:function(xhr,status,error){
29       alert('返回数据异常!');
30     }
31   });
32   return false;
33 }
34 </script>



本文标题:pbootcms使用Ajax无刷新提交留言及表单
本文网址:https://www.hflmwl.com/news/1456.html
原创作者:合肥良马网络科技有限公司 版权所有,转载请注明出处,并以链接形式注明。
声明:本页内容由合肥良马网络科技有限公司通过网络收集编辑和原创所得,所有资料仅供用户参考;本站不拥有所有权,也不承认相关法律责任。如您认为本网页中有涉嫌抄写的内容,请及时与我们联系进行举报,并提供相关证据,工作人员会在5个工作日内联系您,一经查实,本站将立刻删除涉嫌侵权内容。如果您对SEO优化核心技术文章感兴趣,请点击查看网络推广网站制作的相关文章,请关注良马科技官网(www.hflmwl.com)

推荐文章

相关文章