学习资料_文档下载_软件应用_程序模板

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

搜索
查看: 2813|回复: 0

PbootCMS使用Ajax无刷新提交留言及表单

[复制链接]

295

主题

297

帖子

787

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
787
发表于 2024-12-17 10:55:41 | 显示全部楼层 |阅读模式
留言表单
  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提交
  1. <script>
  2. //ajax提交留言,由于涉及到提交地址标签的解析,JS需要放在html文件中
  3. function submsg(obj){
  4.   var url='{pboot:msgaction}'; //如果是自定义表单则使用地址{pboot:form fcode=*}
  5.   var contacts=$(obj).find("#contacts").val();
  6.   var mobile=$(obj).find("#mobile").val();
  7.   var content=$(obj).find("#content").val();
  8.   var checkcode=$(obj).find("#checkcode").val();
  9.   
  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>
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

HI223.COM 举报邮箱:345306361@qq.com

GMT+8, 2025-7-4 07:30 , Processed in 0.057480 second(s), 19 queries .

Powered by HI223分享社区 2.3

© 2019-2020 Hi223 All Right Reserved

渝公网安备 50022502000358号

渝ICP备14008270号-3